Hex programming
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
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?
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?
-------------------------------NeXe: NeHe DirectX-style. Follow the orange rabbit.
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
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
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
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
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
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?
_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?
Yah, 10 is 16
Sorry for the confusion, it''s early here and I''m tired
Sorry for the confusion, it''s early here and I''m tired
-------------------------------NeXe: NeHe DirectX-style. Follow the orange rabbit.
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.
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.
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement