binaryhexoctalnumbers

advertisement
Why do computer geeks celebrate Halloween on Christmas? Because Oct 31 is equal to Dec 25. Get
it? You don't? Really? Well, I suppose if I need to explain the joke, it probably isn't funny, but I
won't let that stop me. If you haven't a clue what I'm talking about, you probably never learned
about binary, hexadecimal, or octal numbers - so let me explain.
Most people use the decimal system (sometimes abbreviated as dec) when they count. It goes
something like this: We start off at 0 and continue up to 9, where we run into a problem. Most of us
know the next number's 10, but mathematically speaking, we've run out of symbols. So how do we
get from 9 to 10? Well, since the number 9 can also be represented as 09, we bump the 0 up to 1 and
cycle the 9 back to 0, which, of course, produces the number 10.
Then we continue: 11, 12, 13, all the way up to 19. Then we pop up the digit in the tens place to 2
and move the 9 back 0 again. Now we have 20. This system is also called base 10.
The number 25 can be expressed mathematically like this:
25 = (2 x 10) + (5 x 1)
Notice, the 2 is in the tens place and the 5 in the ones place. Here's another way to say the same
thing, using exponents:
25 = (2 x 101) + (5 x 100)
If you don't remember much about exponents, here's a table to help:
100 101 102 103
104
1 10 100 1,000 10,000
105
100,000
Let's look at another example.
1492 = (1 x 103) + (4 x 102) + (9 x 101) + (2 x 100)
Here, the 1 is in the thousands place, the 4 is in the hundreds place, the 9 is in the tens place, and the
2 is in the ones place. If you're having trouble catching on, try a couple of your own numbers.
Computers use electrical impulses to represent numbers (and everything else for that matter). Since
there are only two kinds of electronic impulses - those that don't exist and those that do - they can
be represented by two numbers: 0 and 1. For example, four cycles of electricity that don't exist are
represented by the binary number 0000, which is equal to the decimal value 0.
To continue counting from 0000, we move on to 0001, where we find ourselves out of symbols again,
so we just do the same thing we did before: We bump the second digit from the right to 1, and cycle
the first to 0, producing the binary number 0010, which is equal to the decimal value 2. This system
is called base 2 or binary, and is sometimes abbreviated as bin.
Here's a table that shows the first 16 binary numbers and their equivalent decimal values:
Dec 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Bin 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Converting binary to decimal is pretty easy. In the places where we had a 10 in the previous
equation we put a 2. Let's try it using the binary number 11001.
bin 11001 = (1 x 24) + (1 x 23) + (0 x 22) + (0 x 21) + (1 x 20) = 25
or:
bin 11001 = (1 x 16) + (1 x 8) + (0 x 4) + (0 x 2) + (1 x 1) = 25
On the right is the ones place, followed by the twos place, followed by the fours place, right on up to
the sixteens place. Converting binary to decimal isn't hard if you just remember the first digit on
the right is the ones place, and double the value of each successive place.
bin 0
1 1 0 0 1
x (32 16 8 4 2 1)
0 + 16 + 8 + 0 + 0 +1 = 25
You got it now, right? I bet you can convert binary to decimal like a pro. Give it a try on some
smaller examples. You can use a pencil and paper, but no calculators! If that's too easy for you, try
some larger problems.
Now get ready for hexadecimal numbers, but don't get too excited. There's no Saint Nick or Great
Pumpkin yet.
For large numbers, binary representation gets a little clumsy. Using the decimal system, the value
25 is only two digits, but in binary it's five: 11001. Our Binary Values table shows that with four
binary digits, we can represent 16 decimal system values (0 through 15). Hexadecimal numbers
(also known as base 16 and sometimes abbreviated as hex) are also used to represent these 16
values. If you've ever changed the background or font colors on a Web page, you've probably run
across a few hex numbers.
In decimal, we have ten symbols that represent all the numbers, and in binary, we have two
symbols, but in hexadecimal, we need sixteen! We use 0 through 9 to represent the equivalent
decimal values, and the letters A through F to represent decimal values 10 through 15.
Hexadecimal and Binary Values
Dec
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Bin 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
The number hex 19 can easily be converted to bin 00011001 (hex 1 = bin 0001 and hex 9 = bin 1001)
and then to our familiar decimal number, 25. But it's usually faster to go directly from hexadecimal
to decimal. To do this, we use the same kind of equation we used to convert binary to decimal, but
this time we use 16s instead of 2s:
hex 19 = (1 x 161) + (9 x 160) = 25
Here's an easy way to apply this new knowledge of yours. HTML colors are represented by three
sets of two-digit hex numbers. If you can convert from base 16 to base 10, you can convert
hexadecimal color values to RGB (red, green, blue) values, which are used in other graphics
software, such as Photoshop and HTML Color Picker.
The first two numbers of a hexadecimal color control the intensity of red. The next two adjust
green, and the next pair blue. For example, a bright red color is represented with the hexadecimal
number FF0000. This color has the most red you can have (hex F = dec 15) and not a spec of green
or blue. The number hex FF can easily be converted to decimal:
hex FF = (F x 161) + (F x 160)
(15 x 161) + (15 x 160) = 255
What's 15 times 16, plus 15? Where's my calculator? Let's see, here. It's 255, and well, what do you
know? In RGB values, that's 100 percent saturation red.
If you're feeling really smart, try converting some more two-digit hex numbers to decimal. You can
use your calculator this time, but no calculators that automatically convert bases!
If you're having problems converting hexadecimal to decimal, don't worry about it. It may just take
a while to get the hang of it.
When do the "Ho, ho, ho" and the ghosts and ghouls come into this? We're almost there.
One hexadecimal number represents four binary digits. But sometimes a number that represents
three binary digits is used. This is called base 8, or octal numbers. Octal is sometimes abbreviated
oct.
Octal Values
Oct
0
1
2
3
4
5
6
7
Bin 000 001 010 011 100 101 110 111
The symbols 8 and 9 aren't used in the base 8 system. Instead, we skip to oct 10 after oct 7. Now this
may seem a little confusing, but oct 10 is actually equal to dec 8, and oct 11 represents the decimal
value 9. Using the above chart, the number oct 31 can be converted to bin 011001, and then
converted to decimal:
bin 011001 = (0 x 25) + (1 x 24) + (1 x 23) + (0 x 22) + (0 x 21) + (1 x 20) = dec 25
Or you can convert octal straight to decimal:
oct 31 = (3 x 81) + (1 x 80) = dec 25
So oct 31 is equal to dec 25, get it? Octal 31 has the same value as decimal 25. Both octal and
October are abbreviated as oct and both December and decimal are abbreviated as dec. October 31
is Halloween and December 25 is Christmas. Ha ha! He he? Ho ho.
Download