190. Reverse Bits (Binary)

>>>表示无符号右移,左边空出的位以0填充
>>=右移赋值
>>>=无符号右移赋值
<<= 左移赋值
<<左移

 1 class Solution {
 2     // you need treat n as an unsigned value
 3     public int reverseBits(int n) {
 4         int res = 0;
 5         for(int i = 0; i < 32; i++) {
 6             res <<= 1;
 7             res += n & 1;
 8             n >>>= 1;
 9             
10         }
11         return res;   
12     }
13 }

猜你喜欢

转载自www.cnblogs.com/goPanama/p/9393857.html