0

I am a newbie in python. Can some one advice how can I convert a hex number to its string representation.I would like to implement something like below.What should be the best method for 'convert()'?

val_hex = 0xBEEF
val_str = convet(val_hex) # val_str = 'BEEF'
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
ZeeBlue
  • 17
  • 6

1 Answers1

0

Could using builtin function hex, which convert an integer number (of any size) to a lowercase hexadecimal string prefixed with “0x”

hex(val_hex)  # ==> 0xbeef

Or using format % values, X means signed hexadecimal (uppercase)

'%X' % val_hex  # ==> BEEF
Jacky1205
  • 3,273
  • 3
  • 22
  • 44