how to make range in hexadecimal python?

Viewed 2596

I want to make a range in python from variable a and variable b

a = 0x88
b = 0xff
for x range(a, b):
    print(x)

from my code the result like this 136, 137, 138, 139 ...

but I want the result of looping like this

88, 89, 8a, 8b, 8c, 8d, 8e, 8f, 90, 91 .... ff

please help me, thank you

2 Answers

You can use hex(x) to convert x to a hexadecimal number.

Therefore your code will look like this:

a = 0x88
b = 0xff
for x in range(a, b):
    print(hex(x))

Use hex() function:

a = 0x88
b = 0xff
for x in range(a, b):
    print(hex(x))

results in:

0x88
0x89
0x8a
0x8b
0x8c
0x8d
0x8e
0x8f
0x90
0x91
0x92
0x93
0x94
...
Related