29

I'm doing some binary operations which are often shown as hex-es. I have seen both the 0x and \x as prefixes.

In which case is which used?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
TheMeaningfulEngineer
  • 14,469
  • 22
  • 79
  • 138

2 Answers2

45

0x is used for literal numbers. "\x" is used inside strings to represent a character

>>> 0x41
65
>>> "\x41"
'A'

>>> "\x01" # a non printable character
'\x01'
John La Rooy
  • 281,034
  • 50
  • 354
  • 495
-3

0x follows number, means HEX number

\x follows number, means HEX ascii characters

check it here: ascii table

Euler
  • 285
  • 2
  • 5
  • 13