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);
How do I do that in Python?
For manipulating the bits, there is a special kind of sets of bitwise operators in Python like
OPERATOR
DESCRIPTION
SYNTAX
&
Bitwise AND
x & y
|
Bitwise OR
x | y
~
Bitwise NOT
~x
^
Bitwise XOR
x ^ y
>>
Bitwise right shift
x>>
<<
Bitwise left shift
x<<
Consider the below example :
To perform left shift in python be careful as Python integers aren't fixed-width so we have to use bit masks to obtain the low order bits.
(B << 5) & 0xffffffff