# why do we need hex ?

This is a discussion on why do we need hex ? within the C Programming forums, part of the General Programming Boards category; i m srry i wanted to ask why do we need hexdecimal in programs instead of just writing the real ...

1. ## why do we need hex ?

i m srry i wanted to ask why do we need hexdecimal in programs instead of just writing the real number ? because its not like instructions or anything i mean like for instance binary can contain inside ints so we can use them to send pieces of information by compressing binries inside ints but why do we need hex ?

2. We don't need hexadecimal representation other than for convenience.

3. Because hex [and octal] and binary are closely related.

If I say to you, what is 4711 in binary, I expect you'll take little bit of time to come up with the correct answer (as a 16-bit number it is 0001 0010 0110 0111)

If on the other hand I tell you that hex digits translate to binary as follows
Code:
```0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001
A = 1010
B = 1011
C = 1100
D = 1101
E = 1110
F = 1111```
and asked you to translate 1267, what how long would it take you?

Try both, and tell me which is quicker...

--
Mats

4. Because computers work in binary and hex translates very well to binary (binary itself would be somewhat too hard to read for humans). It's much harder to convert decimals to binary in one's head.

so when we put a hex number than a normal int it translates faster than binary so its somewhat sufficient ?

6. and because 2 hex digits fix perfectly into 1 byte.

7. so when we put a hex number than a normal int it translates faster than binary so its somewhat sufficient ?
It's not faster, just convenient for reading.

Depending on how you think of it, all of your base 10 constants get converted into binary (or hex) when compiled.

8. Simply put, if you want to describe bits (binary digits), hex is excellent, e.g. 2^10 = 0x400 = 1024 - they all become exactly the same for the computer 0010 0000 0000 is the binary value. If you want to say one thousand, then 0x3E8 is just cryptic. But if you want to know which bits are set in a "random" number, such as 43, then it's not so easy. It's much easier if the number is 0x2B - it turns out to be 0010 1011.

Sorry, I missed a bit of my "challenge" in the original reply: Convert 0x1267 to binary. Also convert 4711 in decimal to binary. Which will you do faster (not using a calculator or computer)?

There is absolutely not NECESSITY to use hex - it's just a convenient way to describe large binary valules without loosing the binary-ness.

--
Mats

9. You guys totally missed the opportunity to play the "to summon demons" joke.

Quzah.

i m srry i wanted to ask why do we need hexdecimal in programs instead of just writing the real number ?
What makes you think that writing the number in decimal is more "real" than writing it in hex?

11. Originally Posted by quzah
You guys totally missed the opportunity to play the "to summon demons" joke.

Quzah.
to summon satan himself, either use hex or listen to britney spears...! now pheer phoolis mortal!!

(it kinda sucked i know...)

12. Originally Posted by quzah
You guys totally missed the opportunity to play the "to summon demons" joke.
So, who wants to buy my hex inverters?