Skip to content

算法练习:位运算和数学问题(Bit Manipulation & Math) #27

@ShannonChenCHN

Description

@ShannonChenCHN

题目列表

位运算

数学问题

总结

  1. 把一些常用的位运算特点背下来
    • &,或 |,非 ~,异或 ^,左移 <<,右移 >>
    • (x & 1) == 1 等价于 (x % 2 == 1)
    • (x & 1) == 0 等价于 (x % 2 == 0)
    • x / 2 等价于 x >> 1
    • x &= (x - 1) 把x最低位的二进制1给去掉
    • x & -x 只保留最低位的1,而把其他位的1都去掉
    • x & ~x 得到 0
  2. 异或运算也是一个考点
    • x^0 = x
    • x ^ x = 0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions