Convert hex to binary


Question

I have ABC123EFFF.

I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).

How?

1
87
5/14/2016 2:36:38 AM

For solving the left-side trailing zero problem:


my_hexdata = "1a"

scale = 16 ## equals to hexadecimal

num_of_bits = 8

bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)

It will give 00011010 instead of the trimmed version.

95
12/1/2011 10:17:47 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon