Through the code for i in range(2000,50000) I want to output the numbers from 2000 to 50000 in the following string format:
when i = 2000
output : 07 D0
When i = 50000
output : C3 50
How can I do that?
>Solution :
You can try this way:
def format_hex(number):
# convert to hex string
hex_str = hex(number)
# upper case
hex_str_upper = hex_str.upper()
# format
hex_value = hex_str_upper[2:]
if len(hex_value)==3:
hex_value = '0' + hex_value
hex_value_output = hex_value[:2] + ' ' + hex_value[2:]
return hex_value_output