Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- // you need treat n as an unsigned value
- public int reverseBits(int n) {
- int result = 0;
- for (int i = 0; i <= 31; i++) {
- int bit = (n >> i) & 1;
- if (bit == 1) { // If n's i-th bit is true, then
- result |= 1 << (31 - i); // set true the result's (31-i)-th bit.
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement