6

Possible Duplicate:
Why are Hexadecimal Prefixed as 0x?

I just saw a comment a friend of mine made:

3x12=36
2x12=24
1x12=12
0x12=18

Which made me wonder..
Why did they choose 0x as prefix for hexadecimal numbers? Is there any history behind this decision?

Community
  • 1
  • 1
default
  • 11,485
  • 9
  • 66
  • 102
  • 1
    you mean what is the history of 0x as a prefix vor hex-numbers? – Hinek Nov 23 '10 at 15:30
  • @Hinek: exactly. why `0x` and not `0?` or `_` or any other character.. – default Nov 23 '10 at 15:31
  • 3
    different languages systems actually have [a lot of ways](http://en.wikipedia.org/wiki/Hexadecimal#Representing_hexadecimal) to represent hexadecimal, both prefix and suffix, using `0`, `h` and even `$` and `\\`. – Andrzej Doyle Nov 23 '10 at 15:33
  • In C you can type in numbers in three formats: A: decimal -> starting with 1 to 9 B: octal starting with 0 (like 037) C: hexadecimal starting with 0x One only needed some seperation – Traummaennlein May 15 '17 at 12:16

4 Answers4

5

I think, because x comes from hex and 0 is to indicate that it is a number.

khachik
  • 28,112
  • 9
  • 59
  • 94
1

0x means the number is probably hexadecimal. This applies in C/C++, and probalby other languages.

His comment is a joke. he starts with multiplication tables for the number 12, but when he gets to 0 he implies that 0x is not "0 multiplied by...", but instead is "hexadecimal" so 12 in hex is 18 in decimal.

FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
0

It's a joke on HEX numbers from WIKIPEDIA.

The first three are interpreted as multiplication, but in the last, "0x" signals Hexadecimal interpretation of 12, which is 18.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
0

'0x' means that the number that follows is in hexadecimal. It's a way of unambiguously stating that a number is in hex, and is a notation recognised by C compilers and some assemblers

J Benjamin
  • 4,722
  • 6
  • 29
  • 39