Convert hex to binary Convert hex to binary python python

Convert hex to binary


For solving the left-side trailing zero problem:


my_hexdata = "1a"scale = 16 ## equals to hexadecimalnum_of_bits = 8bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)

It will give 00011010 instead of the trimmed version.


import binasciibinary_string = binascii.unhexlify(hex_string)

Read

binascii.unhexlify

Return the binary data represented by the hexadecimal string specified as the parameter.