Skip to content Skip to sidebar Skip to footer

How To Decode Raw Binary To Hex

I'm required to decode a raw binary value that looks like b'\xa3\x13\xa4;\xcb\xda\x1b\x1b,Ut\xde\xeb2\xb5\x84\xe5&\x85;' to a hex value which then would look like 0x90D152B5ED5

Solution 1:

Use binascii.hexlify

>>>x = b'\xa3\x13\xa4;\xcb\xda\x1b\x1b,Ut\xde\xeb2\xb5\x84\xe5&\x85;'>>>binascii.hexlify(x).decode()
'a313a43bcbda1b1b2c5574deeb32b584e526853b'

Convert it to number using int with base parameter as 16:

>>>int(binascii.hexlify(x), 16)
931003516565576134942949873523045876335469036859
>>>int(binascii.hexlify(x), 16) == 0xa313a43bcbda1b1b2c5574deeb32b584e526853b
True

Post a Comment for "How To Decode Raw Binary To Hex"