#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

quote:

I''m lookin for a tutorial or something on hexadecimal numbers. I understand the basic premise, ie 0-9, a= 10, b=11, f=15..and combining them: 2f = 47, 3a = 58.
But i get lost when you get things like this: 0x8000...I''m pretty sure its hexadecimal, I just don''t know what it is. Can anyone point me in the right direction?

Thanks,
-Chris

It is pretty simple really it just 16 base airthmetic instead of base 10. So 0x8000 is equivalent to:
8*16^3 == 8*4096 == 32768

the 16^3 comes from the position of the 8 which is 3 starting with 0. If you had 0x8001 base is equivalent to:
8*16^3+1*16^0 == 8*4096+1 = 32769

If you had 0x80021, this is equvalent to:
8*16^3 + 2*16^1 + 1*16^0 == 8*4096+2*16+1 == 32768+32+1 == 32801

If you are working on a windows system, take a look at the calculator. Under the view menu option is a scientific option, this has an option to allow you to convert hex to dec to bin and vice versa. Good Luck.

##### Share on other sites
Usually when you write a hex value out like that, it''s because you want a specific bit pattern, and it''s easier to convert from binary to hex than from binary to decimal. For instance, your example of 0x8000 reminds me of using GetAsyncKeyState(). Have a look:

#define KEYSTATE(n) ((GetAsyncKeyState(n) & 0x8000) ? TRUE : FALSE)

GetAsyncKeyState() returns the status of a key in the high bit -- that means the most significant bit of a number. So in order to clear out all the other bits, we AND it with 0x8000, which is equal to:

1000 0000 0000 0000

in binary. That clears all the bits except the high bit, and extracts it. Usually when you use hex in programming it will be for stuff like this, so you don''t need to worry about multiplying by 4096 or whatever to convert hex to decimal. You''ll be more concerned with converting hex to binary, which is trivial because each hex digit corresponds exactly to four binary digits. That is, a hex digit A for instance will always produce a bit pattern of 1010 no matter which other hex digits are surrounding it.

I''m tired... so I hope that made sense.

-Ironblayde
Aeon Software

The following sentence is true.
The preceding sentence is false.

##### Share on other sites
I''m lookin for a tutorial or something on hexadecimal numbers. I understand the basic premise, ie 0-9, a= 10, b=11, f=15..and combining them: 2f = 47, 3a = 58. But i get lost when you get things like this: 0x8000...I''m pretty sure its hexadecimal, I just don''t know what it is. Can anyone point me in the right direction? Thanks, -Chris

##### Share on other sites
the reason its 0x8000 is because in C, hex is usually represented as 0xnumber
all it means to the compiler is "interpret this number as a hex number"

you do know how it all works dont you?
in base 16, you have something like

0x68204
which is
(4 * 16^0) + (0 * 16^1) + (2 * 16^2) + (8 * 16^3) + (6 * 16^4)

it follows the same principle as base 10(decimal), its just base 16

##### Share on other sites
If I understood your post correctly I think Quantum gave you the answer you wanted.

YAP-YFIO,

##### Share on other sites
i learned some good hexadecimal and binary stuff in the first chapter of 'Art of Assembly'. it doesn't take long to get through the first chapter... and there are a few exercises if you wanted to at the end of the chapter.

you can get it at:

Here

Dong

Edited by - dong on October 29, 2000 9:36:14 AM

• ### Forum Statistics

• Total Topics
628394
• Total Posts
2982428

• 10
• 9
• 19
• 24
• 9