码迷,mamicode.com
首页 > 其他好文 > 详细

190. Reverse Bits (Binary)

时间:2018-07-31 11:17:48      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:solution   sig   value   signed   ever   style   赋值   sign   bin   

>>>表示无符号右移,左边空出的位以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)

标签:solution   sig   value   signed   ever   style   赋值   sign   bin   

原文地址:https://www.cnblogs.com/goPanama/p/9393857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!