Hexadecimal goes from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
I am confused as to where the 'x' in '0x0f' comes from.
And if '0x0f' = '0000 1111' or '15' why not just write '0f'.
Pretty sure this is universal across most languages, but if not, I'm using Java.
Thank you.
32 Answers
It's historic, with Java inheriting that syntax from C.
The x is necessary to distinguish 0377 (for example) from 0x377, where the leading zero in the former indicates that it's in octal (base 8):
377 - base 10 0377 - base 8 0x377 - base 16 1See the JLS:
In a hexadecimal or binary literal, the integer is only denoted by the digits after the 0x or 0b characters and before any type suffix. Therefore, underscores may not appear immediately after 0x or 0b, or after the last digit in the numeral.
It's used in order to distinguish between bases.
0