1. 程式人生 > >190. Reverse Bits (Binary)

190. Reverse Bits (Binary)

reat rev style val you value class sig ++

>>>表示無符號右移,左邊空出的位以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 }

190. Reverse Bits (Binary)