Don't encode to hex at all; just use data
directly and use the ord()
function to turn the bytevalue into an integer; you don't want the hex representation here
ord(data) & 1
If you did cast to hex, you'd have to interpret the value as a hexadecimal integer:
int(st, 16) & 1
but with the encoding to hex that's more work than is required.
Demo:
>>> data = '\x3a'
>>> ord(data)
58
>>> ord(data) & 1
0
>>> int(data.encode('hex'), 16)
58
>>> int(data.encode('hex'), 16) & 1
0