How do I manipulate bits in Python?

后端 未结 9 1872
借酒劲吻你
借酒劲吻你 2020-12-12 22:37

In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:

unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 23:05

    Python has C style bit manipulation operators, so your example is literally the same in Python except without type keywords.

    value = 0xdeadbeef
    value &= ~(1 << 10)
    

提交回复
热议问题