public int reverseBits(int n) { int ret = 0; int count = 32; while (count-- > 0) { int lastBit = n & 1; //获取 n 最后一位 ret = ret << 1 | lastBit; //将结果左移一位后再添加 n 的最后一位 n = n >> 1; // n 右移来减少一位 } return ret; }
利用位运算,逆序二进制数字
原创wx637f0ba1ddc42 博主文章分类:数据结构+LeetCode ©著作权
©著作权归作者所有:来自51CTO博客作者wx637f0ba1ddc42的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:深度有限搜索:获取岛屿的最大面积
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
交替位二进制数字
给定一个正整数,检查他是否为交替位二进制数:换句话说,
交替位二进制数字 位运算 二进制数