Complete-Preparation

πŸŽ‰ One-stop destination for all your technical interview Preparation πŸŽ‰

View the Project on GitHub

190_reverseBits 🌟

Reverse bits of a given 32 bits unsigned integer.

Note:

Using lsb

Code

class Solution{
public:
	uint32_t reverseBits(uint32_t n){
		int res = 0;
		for (int i = 0; i < 32; i++){
			int lsb = n & 1;
			int reverseLsb = lsb << (31 - i);
			res |= reverseLsb;
			n = n >> 1;
		}
		return res;
	}
};