We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7d5dcd6 commit c3bcdfdCopy full SHA for c3bcdfd
src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java
@@ -32,9 +32,9 @@ public static int reverseBits(int n) {
32
int result = 0;
33
int bitCount = 32;
34
for (int i = 0; i < bitCount; i++) {
35
- result <<= 1;
36
- result |= (n & 1);
37
- n >>= 1;
+ result <<= 1; // Left shift the result to make space for the next bit
+ result |= (n & 1); // OR operation to set the least significant bit of result with the current bit of n
+ n >>= 1; // Right shift n to move on to the next bit
38
}
39
return result;
40
0 commit comments