Explain to me where the “x” in the hexadecimal “0xf0” comes from

Hex is coming from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

I am confused as to where it comes 'x'from '0x0f'.

And if '0x0f' = '0000 1111'or '15'why just write '0f'.

Pretty sure this is universal for most languages, but if not, I use Java.

Thanks.

+4
source share
2 answers

This is historical, with Java inheriting this syntax from C.

x it is necessary to distinguish 0377 (for example) from 0x377, where the initial zero in the first indicates that it is in octal (base 8):

   377 - base 10
  0377 - base 8
 0x377 - base 16
+11
source

See JLS :

0x 0b . 0x 0b, .

.

+1

Source: https://habr.com/ru/post/1526700/


All Articles