Skip to content

Commit 26af651

Browse files
authored
Create 190. Reverse Bits
1 parent 468386b commit 26af651

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Bit Manipulation/190. Reverse Bits

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
uint32_t reverseBits(uint32_t n) {
4+
uint32_t res = 0 ;
5+
6+
for(int i = 0 ; i < 32 ; i++)
7+
{
8+
res = (res << 1) + ( n & 1) ; // left shift res and doing & opertator
9+
10+
n = n >> 1 ; // right shift the main integer
11+
12+
}
13+
14+
return res ;
15+
16+
}
17+
};

0 commit comments

Comments
 (0)