Forum



Hexadecimal constant
8 replies



hexadecimal = base 16
chars 0 - 9 = values 0 - 9
chars A - F = values 10 - 15
just read the wiki page to learn how it works:
http://en.wikipedia.org/wiki/Hexadecimal
note that "0x" is just a prefix which shows you that the following chars represent a hexadecimal number
0 - 0
1 - 1
...
9 - 9
a - 10
b - 11
...
f - 15
Now when we have two digits, we do what we normally do in base10. We multiply the first digit by 10 (10 = 16 in hex) and then add in the second. So
10 = 1*(10) + 0*(1) = 16 + 0
11 = 1*(10) + 1*(1) = 16 + 1
...
20 = 2*(10) + 1*(0) = 32 + 0
...
a0 = a*(10) + 1*(0) = 160 + 0
...
ff = f*(10) + f*(1) = 240 + 15 = 255
same in 3 digits
a93 = a*(100) + 9*(10) * 3*(1) = 256*(10) + 9*(16) + 3
and in any arbitrary digits...
Even better yet, when you're working with hexadecimal, try not to convert them back into decimal until the end.

edited 1×, last 25.02.11 12:09:36 pm
wikipedia has written
the hexadecimal number 2AF3 is equal, in decimal, to (2 × 16^3) + (10 × 16^2) + (15 × 16^1) + (3 × 16^0) , or 10,995.
converted to your case (FFFF):
1. F=15 => (15 * 16^3) = 15 * 4096 = 61440
2. F=15 => (15 * 16^2) = 15 * 256 = 3840
3. F=15 => (15 * 16^1) = 15 * 16 = 240
4. F=15 => (15 * 16^0) = 15 * 1 = 15
sum: 65535
1
2
3
4
2
3
4
FFA F = 1111 A = 1010 So FFA = 111111111010
1
2
3
4
5
2
3
4
5
FFFF -> 1111111111111111 -> 65535





