Skip to content

Commit c3bcdfd

Browse files
committed
Fix
1 parent 7d5dcd6 commit c3bcdfd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/com/thealgorithms/bitmanipulation/ReverseBits.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public static int reverseBits(int n) {
3232
int result = 0;
3333
int bitCount = 32;
3434
for (int i = 0; i < bitCount; i++) {
35-
result <<= 1;
36-
result |= (n & 1);
37-
n >>= 1;
35+
result <<= 1; // Left shift the result to make space for the next bit
36+
result |= (n & 1); // OR operation to set the least significant bit of result with the current bit of n
37+
n >>= 1; // Right shift n to move on to the next bit
3838
}
3939
return result;
4040
}

0 commit comments

Comments
 (0)