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 }

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

时间: 2024-12-15 11:03:49

190. Reverse Bits (Binary)的相关文章

190. Reverse Bits(leetcode)

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up:If this function

leetcode——190 Reverse Bits(32位无符号二进制数的翻转)

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up: If this function

Leetcode 190. Reverse Bits(反转比特数)

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up: If this function

LeetCode 190. Reverse Bits (反转位)

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). 题目标签: Bit Manipulation 这道题目

【leetcode】Reverse Bits(middle)

Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000). 思路: n一直右移, ans一直左移. class So

338. Counting Bits (Binary)

这个规律找的更好,规律是,从1开始,遇到偶数时,其1的个数和该偶数除以2得到的数字的1的个数相同,遇到奇数时,其1的个数等于该奇数除以2得到的数字的1的个数再加1 1 class Solution { 2 public int[] countBits(int num) { 3 int[] res = new int[num + 1]; 4 res[0] = 0; 5 for(int i = 1; i <= num; i++) { //注意是 <= 6 if(i % 2 == 0 ) { 7 r

谈谈计算机和网络常用进位制:二进制(Binary)、十进制(Decimal)和十六进制(He

谈谈计算机和网络常用进位制:二进制(Binary).十进制(Decimal)和十六进制(Hexadecimal) 二进制.十进制和十六进制,这几个个进制里算十进制我们最熟悉了,从学前教育或者幼儿园最先接触的数学到再我们日常生活几乎天天和他打交道的下面这十个数字. 但是,话又说回来,你真的理解这10个数字吗?或者说你理解十进制吗? 今天我们就以十进制为切入点顺便谈谈二进制.十六进制以及它们之间的转换.在谈这些进制之前我们先了解一下进制的概念: 所谓进制就是进位制,是人们规定的一种进位方法.进位制/

在VC下采用ADO实现BLOB(Binary)数据的存储,读取,修改,删除。

作者:邵盛松 2009-09-05 前言 1关于的BLOB(Binary)数据的存储和读取功能主要参考了MSDN上的一篇<AppendChunk and GetChunk Methods Example (VC++)>,原文地址是http://msdn.microsoft.com/en-us/library/ms807920.aspx.还有www.vckbase.com上有一篇文章<使用ADO实现BLOB数据的存取 -- ADO开发实践之二>,原文地址是http://www.vck

2016.5.16——leetcode:Reverse Bits(超详细讲解)

leetcode:Reverse Bits 本题目收获 移位(<<  >>), 或(|),与(&)计算的妙用 题目: Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in bin