Skip to main content
GameDev.net gamedev.net
🔒 Locked

Hexadecimal help

Started by Turtlebread Oct 29, 2000 at 2:31 AM 4 replies 450+ views
Original Post
Turtlebread
Turtlebread
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
Ironblayde
Ironblayde
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.
"Your superior intellect is no match for our puny weapons!"
Quantum
Quantum
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
deadlinegrunt
deadlinegrunt
If I understood your post correctly I think Quantum gave you the answer you wanted.

Constant numbers that start with 0x or hex. Constant numbers that start with 0 are octal. All others representations should be your standard base10 system.

YAP-YFIO,
deadlinegrunt
~deadlinegrunt
Dong
Dong
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.