i am converting hex data to decimal and the range is from 00 to FF
hex_data = "FF"
int("0x" + hex_data , 16)
returns 255 but when i give 0 as hexdata it gives 0 wheras i need it as 000
how to do it
You need to format it:
hex_data = "FF"
number = int("0x" + hex_data, 16)
print '%03d' % number # either this
print '{:03d}'.format(number) # or this (Python >= 2.6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With