Notice that '10' is the representation of the base in that base:
10 is 2(decimal) in base-2
10 is 3(decimal) in base-3
...
10 is 10(decimal) in base-10
...
10 is 16(decimal) in base-16 (hexadecimal)
...
10 is 1024(decimal) in base-1024
...and so on
It's a hex number and is 16 decimal.
0xNNNN
(not necessarily four digits) represents, in C at least, a hexadecimal (base-16 because 'hex' is 6 and 'dec' is 10 in Latin-derived languages) number, where N
is one of the digits 0
through 9
or A
through F
(or their lower case equivalents, either representing 10 through 15), and there may be 1 or more of those digits in the number. The other way of representing it is NNNN16.
It's very useful in the computer world as a single hex digit represents four bits (binary digits). That's because four bits, each with two possible values, gives you a total of 2 x 2 x 2 x 2
or 16
(24) values. In other words:
_____________________________________bits____________________________________
/ \
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
| bF | bE | bD | bC | bB | bA | b9 | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
\_________________/ \_________________/ \_________________/ \_________________/
Hex digit Hex digit Hex digit Hex digit
A base-X number is a number where each position represents a multiple of a power of X.
In base 10, which we humans are used to, the digits used are 0
through 9
, and the number 730410 is:
In octal, where the digits are 0
through 7
. the number 7548 is:
Octal numbers in C are preceded by the character 0
so 0123
is not 123 but is instead (1 * 64) + (2 * 8) + 3, or 83.
In binary, where the digits are 0
and 1
. the number 10112 is:
In hexadecimal, where the digits are 0
through 9
and A
through F
(which represent the "digits" 10
through 15
). the number 7F2416 is:
Your relatively simple number 0x10
, which is the way C represents 1016, is simply:
As an aside, the different bases of numbers are used for many things.
The simple version is 0x is a prefix denoting a hexadecimal number, source.
So the value you're computing is after the prefix, in this case 10.
But that is not the number 10. The most significant bit 1
denotes the hex value while 0
denotes the units.
So the simple math you would do is
0x10
1 * 16 + 0 = 16
Note - you use 16 because hex is base 16.
Another example:
0xF7
15 * 16 + 7 = 247
You can get a list of values by searching for a hex table. For instance in this chart notice F corresponds with 15.
Source: Stackoverflow.com