I have the following code:
SN.get_Chars(5)
SN is a string so this should give the 5th Char Ok!
Now i have another code but : SN.get_Chars(0x10)
I wonder what 0x10 is? Is it a number? If it's so, then what is it in decimal notation?
I have the following code:
SN.get_Chars(5)
SN is a string so this should give the 5th Char Ok!
Now i have another code but : SN.get_Chars(0x10)
I wonder what 0x10 is? Is it a number? If it's so, then what is it in decimal notation?
0xNNNN
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
(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:
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
(both groups giving 0 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.
Notice that '10' is the representation of the base in the its 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