Hey everyone,

I just recently found out some pretty neat information about binary and hexadecimal. I would like to

share my new found knowledge with the AO community. This information I am about to give you is coming

from my new found knowledge. I used the book Sam's Teach Yourself C++ in 21 Days as a reference.

First, in order to understand binary and hexadecimal, you must think of numbers, not as numbers, but as

ideas. To help you understand what I mean, take the number 3 for example. The number three is an idea,

while the numeral 3 is a symbol used to represent the number three. I am sure you know what I mean when I

write ||| and III. Now that you think of numbers as ideas, we can change the way you see them.

The numberal 15 is consisted of two numbers, 1 and 5. 1 meaning one set of tens, and 5 meaning five sets

of ones. In base 10, you use the numerals 0,1,2,3,4,5,6,7,8,9. When you get to ten, you write 10. This

means 1 set of tens and 0 sets of ones.

Some basic rules can be made from this:

1. Base 10 uses the digits 0-9

2. Each column are powers of ten.

Column: 4 3 2 1

Power: 10^3 10^2 10^1 10^0

Value: 1000 100 10 1

So if you wanted to find the number 124, you would take 124/100=1 with a Remainder of 24. Now you have a

1 in the third column. Then 24/10=2 with a Remainder of 4, so you would have a 2 in the second column.

Last, take 4/1=4. Then you put all of the numbers to get 124.

Binary

Base 2 is the ultimate extension of this idea. There are only two different digits: 0 and 1.

Column: 8 7 6 5 4 3 2 1

Power: 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Value: 128 64 32 16 8 4 2 1

*Note: Dont these numbers look familiar, maybe you have seen then while buying RAM?

Ok, so lets convert the number 87 into binary.

87/128 = 0. Put a 0 in column eight.

87/64 = 1 with a Remainder of 23. Put a 1 in column seven.

23/32 = 0. Put a 0 in column six.

23/16 = 1 with a Remainder of 7. Put a 1 in column five.

7/8 = 0. A 0 in column four.

7/4 = 1 with a Remainder of 3. Put a 1 in column three.

3/2 = 1 with a Remainder of 1. Put a 1 in column two.

1/1 = 1, so put a 1 in the column one.

When you write this out in binary, the columns go 87654321, so 87 in binary would be 01010111. Pretty

neat, huh!

Hexadecimal

Since binary is very hard to understand and slow to read, we started looking for a simpler way to

represent the same values. It turns out that it is very simple to translate base 2 to base 16, or

hexidecimal. In base 16, there are sixteen numerals: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F. A would be the

same as ten in base 10, as F would be the same as fifteen in base 10.

Column: 4 3 2 1

Power: 16^3 16^2 16^1 16^0

Value: 4096 256 16 1

To translate hexadecimal to base 10, you can multiply. Lets take F8C.

F*256 (becuz F is in the third column) = 15*256 = 3840

8*16 = 128

C*1 (becuz C is in the first column) = 12*1 = 12

F8C = 3980

Now lets translate FC from hex into binary. Lets translate hex into base 10, and then base 10 into

binary.

F*16 = 15*16 = 240

C*1 = 12*1 = 12

FC = 252

To translate 252 from base 10 into binary, you need the chart:

Column: 8 7 6 5 4 3 2 1

Power: 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0

Value: 128 64 32 16 8 4 2 1

252/128 = 1 with a Remainder of 124. Put a 1 in column eight.

124/64 = 1 with a Remainder of 60. Put a 1 in column seven.

60/32 = 1 with a Remainder of 28. Put a 1 in column six.

28/16 = 1 with a Remainder of 12. Put a 1 in column five.

12/8 = 1 with a Remainder of 4. Put a 1 in column four.

4/4 = 1 with a Remainder of 0. Put a 1 in column three.

Becuz the Remainder is 0, there is nothing left, and the last two digits are 0's

FC = 252 = 11111100

Now for the trick that makes base 2 and base 16 work together so nicely.

If you treat this number as two sets of four digits, you have 1111 1100.

Take the left set and translate it into base 10. 1111 = 15. Translate 15 into hex and you get F.

Take the right set and translate it into base 10. 1100 = 12. Translate 12 into hex and you get C.

1111 1100

F C

Putting the two hex numbers together is FC. In binary it is 11111100 and in base 10 it is 252. This trick

always works. You will find out that alot of programmers use hex frequently in advanced programming,

although you can work effectively in programming for a long time without using any of this.

I hope that some of you will learn something, as I have. Any errors I missed feel free to correct.

-Ep