Forum

> > Off Topic > Hexadecimal constant
Forums overviewOff Topic overviewLog in to reply

English Hexadecimal constant

8 replies
To the start Previous 1 Next To the start

old Hexadecimal constant

palomino
User Off Offline

Quote
Could anyone explain it to me please? I know the 0xffff stuff, I just can't understand how they for a number. Anyone, please?

old Re: Hexadecimal constant

DC
Admin Off Offline

Quote
decimal = base 10
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

old Re: Hexadecimal constant

Lee
Moderator Off Offline

Quote
0-f corresponds to 0 to 15

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.

old Re: Hexadecimal constant

palomino
User Off Offline

Quote
Thanks for your replies, but I still don't get how 0xffff form 65535
edited 1×, last 25.02.11 12:09:36 pm

old Re: Hexadecimal constant

DC
Admin Off Offline

Quote
then you didn't read the wikipedia link carefully enough
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

old Re: Hexadecimal constant

DannyDeth
User Off Offline

Quote
It's because hexadecimal WAS NOT made as a numbering system on the terms we are used to. If I have 0xFFA then what I actually get is binary:
1
2
3
4
FFA
F = 1111
A = 1010
So FFA = 111111111010
So what it does is replace each Hexadecimal digit with it's binary form. That's why 0xFFFF = 65535, because:
1
2
3
4
5
FFFF
->
1111111111111111
->
65535
Hope it enlightens you a little.
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview