d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > 0x01, 0x04, 0x08. What Do These Mean?
12Next
Add Reply New Topic New Poll
Member
Posts: 2,289
Joined: Jan 2 2005
Gold: 763.00
Jul 1 2006 11:55am
Are they binary codes like

0 = 0
1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111
8 = 1000
...
and so forth?

What is 0x04?
Member
Posts: 1,108
Joined: Apr 11 2006
Gold: 97.25
Jul 1 2006 02:40pm
A way to present hex-numbers.

0x04 = 04 (hex) = 4 (dec) (= 0100 (bin))

Hex-numbers can be easily to "translated" to binary. All you need to do is just "split" the hex in 1 char parts and change it to bin (4 bit)
0xf3 = f 3 = 1111 0011
0x3a94 = 0011 1010 1001 0100

"Translation" from bin to hex is also easy.
0110 0111 1101 1000 = 6 7 D 8
Member
Posts: 645
Joined: May 6 2005
Gold: 0.00
Jul 1 2006 04:04pm
A notation like this is very often used to store information about multiple options with 2 possible states for each option (on, off).

You define it usually this way:
#define OPTION_A 0x0001 // binary: 0000 0001
#define OPTION_B 0x0002 // 0000 0010
#define OPTION_C 0x0004 // 0000 0100
#define OPTION_D 0x0008 // 0000 1000
#define OPTION_E 0x0010 // 0001 0000

e.g. OPTION_B and OPTION_E -> ON: binary 0001 0010 which is 0x12.

Then with just setting or reseting one or more bit using bitmasks (mainly logical AND and logical OR) you can turn on/off options independently from other and check which options are turned on. It let's you store 32 options in one 4 byte integer variable.

I hope it helped you. If you have any more questions about it - just ask wink.gif
Member
Posts: 1,404
Joined: Dec 19 2005
Gold: 712.00
Jul 1 2006 08:39pm
They also could be referenced to "packets" to send information to another.
Member
Posts: 1,108
Joined: Apr 11 2006
Gold: 97.25
Jul 2 2006 02:59am
Sure, but also if they are packets, the are in hex-format (or at least I have thinked so until now biggrin.gif)

Also if you are programming stuff like eproms etc. those are used quite much.
Like PORTB = 0xFF which sets in Atmel's microcontroller's all PORTB's ports (8 ports ofc) to 1 (1111 1111)

Also Konrad told good point. smile.gif

This post was edited by draghas on Jul 2 2006 03:08am
Member
Posts: 2,289
Joined: Jan 2 2005
Gold: 763.00
Jul 2 2006 05:44am
Thanks for all replies, this explains it.

Is there a way to logically translate hex numbers into decimal numbers or do I need a tabular?
Member
Posts: 8,844
Joined: May 21 2005
Gold: 455.03
Trader: Trusted
Jul 2 2006 06:14am
All programming languages have functions 4 it.

... or If U have Excel, U can define function in it

... or use Calculator happy.gif
Member
Posts: 1,108
Joined: Apr 11 2006
Gold: 97.25
Jul 2 2006 10:36am
Logic on "translate" hex to dec is like this:

46A = 16^2 * 4 + 16^1 * 6 + 16^0 * 10 (= is A from hex)

16^2 * 4 = 256 * 4 = 1024
16^1 * 6 = 16 * 6 = 96
16^0 * 10 = 1 * 10 = 10

1024 + 96 + 10 = 1130 (this is dec)

Same system can be used with any numbersystem, example:

100110 = 2^5 * 1 + 2^4 * 0 + 2^3 * 0 + 2^2 * 1 + 2^1 * 1 + 2^0 * 0
2^5 * 1 = 32
2^4 * 0 = 0
2^3 * 0 = 0
2^2 * 1 = 4
2^1 * 1 = 2
2^0 * 1 = 0

32 + 4 + 2 = 38 (dec)

And oct...

153 = 8^2 * 1 + 8^1 * 5 + 8^0 * 3
8^2 * 1 = 64
8^1 * 5 = 40
8^0 * 3 = 3

64 + 40 + 3 = 107 (dec)

Hope you got the point smile.gif
Member
Posts: 2,289
Joined: Jan 2 2005
Gold: 763.00
Jul 4 2006 06:55pm
Ok thanks.

So we use 0, 1, ..., 9, and A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. Got it. smile.gif
Member
Posts: 2,747
Joined: Dec 24 2005
Gold: 366.00
Jul 9 2006 01:59am
hex confuses the shit outta me does anyone know a shit that breaks it down step by step? or can one of you do it lol
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll