Unfortunately python can't read a bit from byte.I have the following some bits:
var1 = 0b00001111 => 15 in decimal
var2 = 0b 00000010 => 2 in decimal
I need to check second bit in var2, or 3th bit in var1.
How to check those?
Unfortunately python can't read a bit from byte.I have the following some bits:
var1 = 0b00001111 => 15 in decimal
var2 = 0b 00000010 => 2 in decimal
I need to check second bit in var2, or 3th bit in var1.
How to check those?
If you have 0010 and want to check second bit is true or false, You can and with 2:
if (0b0010 & 2) == 2 :
print("two is OK")
if (0b0110 & 4) == 4:
print("four is ok")
You can run something like bin(var2)[::-1][1]
to get the second least significant bit.