BM191NumberOf1Bits

来源:互联网 发布:程序员穿女装是什么梗 编辑:程序博客网 时间:2024/05/07 04:41

Pre-defined Methods

  • Integer.toBinaryString(int n) return binary string
  • Integer.toBinaryString(int n).toCharArray() directly to array.

思路


  • 知道可以用位运算,但是不会应用,参考discussion

https://discuss.leetcode.com/topic/57007/java-tle-question/2

  • Use string and array to do compare one by one. There is no unsigned problem.

  • Use %2 to get the bit. But cannot use for negtive. But learn about True Code, Complemental Code and Ones-complement Code

    http://blog.csdn.net/onewalkingman/article/details/3746154

  • 关于位运算

    • >>右移,和>>>无符号右移的区别。

    正数右移,高位用0补,负数右移,高位用1补,当负数使用无符号右移时,用0进行部位(自然而然的,就由负数变成了正数了)
    http://blog.csdn.net/xiaochunyong/article/details/7748713

    0 0
    原创粉丝点击