Is your "byte" an int
? If so, just take bitwise AND (&
) with 1
(or, if you want to be more explicit, the binary literal 0b1
) to get the least significant bit.
>>> x = 14
>>> x & 1
0
>>> x = 15
>>> x & 1
1
Is your "byte" a bytes
object? If so, just index into it and take bitwise AND.
>>> y = bytes([14, 15])
>>> y[0] & 1
0
>>> y[1] & 1
1