How to convert an integer number to hexadecimal string in Python

4 Answers

0 votes
print(hex(255))
print(hex(-3))


'''
run:
 
0xff
-0x3

'''

 



answered Nov 21, 2018 by avibootz
0 votes
print(format(255, '#x'))
print(format(255, 'X'))


'''
run:
 
0xff
FF

'''

 



answered Nov 21, 2018 by avibootz
0 votes
hx = hex(255)

print(hx)

hx += 'f'

print(hx)


'''
run:

0xff
0xfff

'''

 



answered Dec 12, 2018 by avibootz
0 votes
hx = hex(255)

print(hx)

hx += 'f'

print(hx)


'''
run:

0xff
0xfff

'''

 



answered Dec 12, 2018 by avibootz

Related questions

1 answer 161 views
1 answer 208 views
1 answer 287 views
1 answer 159 views
3 answers 344 views
...