Wednesday, October 17, 2007

Project-Lesson #1 Binary

I'm sure you've heard the word binary but might not have a good understanding of what it means. In order to understand my project you really need to understand how data is stored on a computer so I'll attempt to explain binary as best I can.

First, binary is really just all about numbers. When we use numbers in our everyday life it's all about base10. Binary is base2. So what's the difference?

Base10 = 10 values per digit. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base2 = 2 values per digit. 0 and 1

You can have any base you want. In fact base16 is also very important in computers
Base16 (Hexadecimal) = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

The total number of values you can have in any base is equal to this formal
number of digits to the base power

So in base 10 if you have 2 digits (00 to 99) you have 100 possible values or 10^2
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ... 99
In base 2 if you have 2 digits (00 to 11) you have 4 possible values or 2^2
00, 01, 10, 11
In base 16 if you have 2 digits you have (00 to FF) you have 256 possible values or 16^2
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 10, 11, 12 .. FF

All general math works with any base
in base 10 01 + 09 = 10 10-09 = 01
in base 2 01 + 01 = 10 10-01 = 01
in base 16 01 + 0F = 10 10-0F = 01

If you don't understand think back to "carrying the one". 9 + 1 =10.. IN base10, 9 is the highest value you can have before you have to return to 0 and carry the one
In base2, 1 is the highest value you can have before you have to return to 0 and carry the one
In base16, F is the highest value you can have before you have to return to 0 and carry the one


Now you might be asking why the heck do we even bother to use binary? It seems to complicate things not make things simpler. Well the truth is base2 is as simply as we can get it. Think of binary in terms of FALSE and TRUE. Using FALSE/TRUE in conjunction can produce some very complicated results.

How you ask? Well let's take 3 bits and combine them. Think of each bit as either true or false.
We can have
FFF, FFT, FTF, FTT, TFF, TFT, TTF, TTT OR ALSO KNOWN AS
000, 001, 010, 011, 100, 101, 110, 111

8 Total combinations (2^3 = 8)

Now let's assume the three digits correspond to HAS RED, HAS GREEN, HAS BLUE
If we have FFF (000) we have black
if we have FFT (001) we have blue
if we have FTF (011) we have green
if we have FTT (100) we have cyan (GREEN AND BLUE)
if we have TFT (101) we have purple(RED AND BLUE)
if we have TTF (110) we have yellow (RED AND GREEN)
if we have TTT (111) we have white (RED, GREEN AND BLUE)

This is all your computer does. It takes large combinations of bits and interprets them based on very specific meanings for each bit. See the next post for a more detailed example on how a computer can create an image
from bits.

No comments: