I had always been taught 0–9 to represent values zero to nine, and A, B, C, D, E, F for 10-15.
I see this format 0x00000000 and it doesn't fit into the pattern of hexadecimal. Is there a guide or a tutor somewhere that can explain it?
I googled for hexadecimal but I can't find any explanation of it.
So my 2nd question is, is there a name for the 0x00000000 format?
0x simply tells you the number after it will be in hex
so 0x00 is 0, 0x10 is 16, 0x11 is 17 etc
The 0x
is just a prefix (used in C and many other programming languages) to mean that the following number is in base 16.
Other notations that have been used for hex include:
$ABCD
ABCDh
X'ABCD'
"ABCD"X
Yes, it is hexadecimal.
Otherwise, you can't represent A
, for example. The compiler for C and Java will treat it as variable identifier. The added prefix 0x
tells the compiler it's hexadecimal number, so:
int ten_i = 10;
int ten_h = 0xA;
ten_i == ten_h; // this boolean expression is true
The leading zeroes indicate the size: 0x0080
hints the number will be stored in two bytes; and 0x00000080
represents four bytes. Such notation is often used for flags: if a certain bit is set, that feature is enabled.
P.S. As an off-topic note: if the number starts with 0
, then it's interpreted as octal number, for example 010 == 8
. Here 0
is also a prefix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With