package com.code.binary;
/**
* 颠倒给定的 32 位无符号整数的二进制位。
* 示例 1:
* 输入: 00000010100101000001111010011100
* 输出: 00111001011110000010100101000000
* 解释: 输入的二进制串 00000010100101000001111010011100 表示无符号整数 43261596,
* 因此返回 964176192,其二进制表示形式为 00111001011110000010100101000000。
* 链接:https://leetcode-cn.com/problems/reverse-bits
* 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
*/
public class ReverseBit {
public static int reverseBit(int num){
int result = 0;
int bit = 31;
while(num != 0){
result += (num & 1) << bit;
bit --;
num = num >> 1;
}
return result;
}
public static void main(String[] args){
int n = 43261596;
System.out.println(reverseBit(n));
}
}