Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0x00000000 hexadecimal?

Tags:

numbers

hex

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?

like image 246
nhat Avatar asked Mar 02 '12 20:03

nhat


3 Answers

0x simply tells you the number after it will be in hex

so 0x00 is 0, 0x10 is 16, 0x11 is 17 etc

like image 131
jzworkman Avatar answered Sep 28 '22 20:09

jzworkman


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
like image 41
Greg Hewgill Avatar answered Sep 29 '22 20:09

Greg Hewgill


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.

like image 6
Alexey Ivanov Avatar answered Sep 26 '22 20:09

Alexey Ivanov