• ### What is your GameDev Story?

#### Archived

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

# Hex programming

This topic is 6887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Man, i have a major question. I am a beginner programmer and I use a tutorial book. I am having major problems, evryprogram the book shows has hex in it. I would like to know do I need to know hex in order to program games. Im only 13 so learning hex is a hard thing for me. I''m already having enough trouble learning C

##### Share on other sites
Learning Hex shouldn''t be any harder then learning decimal, it''s just another base. decimal = base 10, hex= base 16.
In hex, instead of counting to 9 before you add another digit, you count to 15. Then, every digit after that represents 16 more. EX:
HEX DECIMAL
0 = 0
1 = 1
2 = 2
3 = 3
4 = 4
5 = 5
6 = 6
7 = 7
8 = 8
9 = 9
a = 10
b = 11
c = 12
d = 13
e = 14
f = 15
f0 = 16

note, the a through f can be capitalized. It makes no difference. The last example I showed, f0, is just a combination of f and 0. So, ff wouldbe 255. Get it?

##### Share on other sites
F0 isn''t 16, 10 is. F0 would be 240

##### Share on other sites
Why should learning hex be any harder just because you''re 13? Almost everything is hard in the beginning

You don''t need to learn hex to program games, but it might come in handy when you come across stuff that has hex in it.

A way to easily convert between hex and decimal is to use this nifty little program. You type in a number and it will show up in decimal and hexadecimal.

int main(void)
{
int no;
scanf("%d", &no);
printf("Decimal: %d\nHex: %x", no, no);
}

/. Muzzafarath

##### Share on other sites
Except that F0 is 240 decimal. Once you get to F, it starts over at 10, just like at 9 in decimal it starts over at 10.

Basically Assasin, hex is just a representation of the same number. 24 in decimal is the same as 18 hex. The computer has no idea about the different representations, because its all the same actual number in binary. Its just a different, and often times easier, way for us to represent numbers. If you want, use a calculator to convert the hex to decimal for a while until it makes sense.

Rock

##### Share on other sites
when the number is for example 255 in decimal, it means
_2_*10^2 + _5_*10^1 + _5_*10^0 (2*100+5*10+5*1).
there are powers of 10

same way for 16base, but there are powers of 16
for example 0x255 is
_2_*16^2 + _5_*16^1 + _5_*16^0 (2*256 + 5*16 +5*1)
so 0x255 hexadecimal is 597 decimal

clear now?

##### Share on other sites
Yah, 10 is 16
Sorry for the confusion, it''s early here and I''m tired

##### Share on other sites
man im only taking seq math1 you guys are confusing me. Whats the point of using hex anyways. Why cant we stick to our normal Base 10 numbering system. Hex is confusing a little. BTW i made a program like that that converts regular characters into ASCII characters.
And a better code for that program you made would be

#include
#include

main()
{
int x;
printf("type in the character you would like to convert into hex\n");
printf("You typed: %d in decimal\n You typed: %x in hex\n", x, x);
system("Pause");
return 0;
}

works the same way just that it doesnt close the program in a blink of the eye.

##### Share on other sites
umm the two header files you should include are stdio.h and stdlib.h ok, sorry bout that, and what does teh Ox stand for

##### Share on other sites
0x tells the C compiler to treat the number as hex and not decimal. Otherwise the compiler wouldn't know what you meant if set a variable equal to 22 (could be 22 decimal, or 34 decimal if treated as hex).

Hex is easier to use for doing things like bit masking (it is easy to read 0x48 and to understand what bits are on and which ones are off). It is very hard to tell at a glance what bits are on for the number 72 decimal. You can use decimal numbers for everything, but there are places where hex is easier to read and understand.

Rock

Edited by - Rock2000 on 3/11/00 12:43:44 PM

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634076
• Total Posts
3015353
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!