I have a list of hex numbers:
[0xaa4d, 0x4643, 0x3353, 0x074c, 0x4854, 0x4138]
My goal is to convert it to something like this:
aa4d46433353074c48544138
What I've tried:
list = [0xaa4d, 0x4643, 0x3353, 0x074c, 0x4854, 0x4138]
string = ''.join('%02x' % i for i in list)
The output is:
aa4d4643335374c48544138
So, it's seems like OK, but, as we see, the output is somehow different from what I need, because 0x074c
converts to 74c
instead of 074c
I've also tried this:
l = [0xaa4d, 0x4643, 0x3353, 0x074c, 0x4854, 0x4138]
s = ''.join('{:02x}'.format(i) for i in l)
print(s)
This still gives me wrong results. I've also tried different numbers at '{:02x}'
& '%02x'
, but still no luck.
My thoughts that converting hex to string removes leading zeros, but I don't know how to do it right.
My question is how to convert 0x074c
to 074c
without losing leading zero. Cause my code gives me 74c
instead.
What am I missing here?