
Copyright
1995 By: John Selvia
This site is part of lyzrdstomp.com.
Binary
is the language of computers. Everything you type, input, output, send,
retrieve, draw, paint, or place blame on when something doesn't work
is, in the end, converted to the computer's native language binary.
But just how does this whole "on/off", "1/0", "hi/lo" thing work?
Binary
is called a Base 2 numbering system (the "bi"
in the word binary was a dead giveaway). Base 2
allows us to represent numbers from our Base 10
system (called the decimal system  "dec" meaning 10) using only 2 digits
 1 and 0  in various combinations.
Example
of a typical binary number: 10001010
8bit binary
number representing the decimal number 138.
To the
computer, binary digits aren't really 1s and 0s. They're
actually electrical impulses in either a (mostly) on state or
a (mostly) off state. Just like a switch  either on or off.
Since you only have 2 possible switch combinations or electrical possibilities,
the computer only needs various combinations of 2 digits to represent
numbers, letters, pixels, etc. These 2 digits, for our sake are visually
represented by 1s and 0s.




Bits,
Bytes and Words


Binary
numbers can be from 1 digit to infinity. But for our uses, there aren't
too many numbers that we can't live without that can't be represented
by 32bit or 64bit binary numbers. Let's start with the basics.
A single
binary 1 or a single binary 0 is called a bit ,
which is short for "binary digit". A single bit by itself
isn't of much use to the casual user, but can do wonders in the hands
of a programmer working at the system level.
Take 4
of these bits and slap them together and they now form what's
called a nibble (though this term isn't used very often). A nibble
can represent the decimal values 0 to 15 (16 distinct values).
4bit
(Nibble) Sample
Take 8
bits and put them together and you have one of the mostly commonly
used computer terms in existence  the byte. A single byte
can represent the decimal values 0 to 255 (256 distinct values)
and since every possible character you can type on an English keyboard
is represented by a number less than 128 to the computer (called ASCII
codes) , a single letter of the alphabet takes 1 byte to represent
internally (technically, you can represent all the letters of the alphabet
using only 7bits of a byte, but we won't get into that). When we speak
of how much ram a computer has, we say it has 256megabytes of ram,
meaning 256 million bytes (most people nowadays just say 256
megs of ram and leave off the byte word).
8bit
(1 Byte) Sample
Place a
couple of bytes together to represent a single value and you have a
16bit word (2 bytes = 16bits). A 16bit word can represent
the values 0 to 65535 (65536 distinct values). In the old days
16bit words were used to form the addresses of 8bit computers
such as the Commodore 64, the Atari 800, and the Apple IIs, to name
a few. These 16bit words which were big enough to store an address
for a 64k computer consisted of 2 bytes, a high byte and a low byte.
1
BYTE

1
BYTE

1

0

0

0

1

0

1

0

1

0

0

0

1

0

1

0

16bit
(2 Byte) Sample
32bit
words are 4 bytes in length. They can represent a value from 0 to 4,294,967,295
(4,294,967,296 distinct values).
1
BYTE

1
BYTE

1
BYTE

1
BYTE

1

0

0

1

1

1

0

1

1

0

0

0

0

1

1

1

0

1

1

0

0

1

1

1

0

1

0

0

0

1

1

1

32bit
(4 Byte) Sample
Pretty
big number, but bigger still is the 64bit word, which is, for you mathdeprived
people, 8 bytes in length (8 bytes times 8 bits per byte).
1
BYTE

1
BYTE

1
BYTE

1
BYTE

1
BYTE

1
BYTE

1
BYTE

1
BYTE

1 
0 
1 
1 
0 
0 
0 
1 
1 
1 
1 
0 
1 
1 
0 
0 
0 
0 
1 
0 
1 
1 
0 
1 
1 
1 
0 
1 
1 
0 
1 
1 
0 
0 
0 
0 
1 
1 
1 
0 
1 
0 
0 
0 
0 
0 
0 
0 
1 
1 
1 
1 
1 
0 
1 
0 
0 
1 
1 
0 
0 
0 
1 
1 
This
whopping monstrosity can represent a number from 0 to 1.844
E+19 if I understand my calculator correctly.



Okay, enough
about bits, bytes and words. Let's figure out how to read a lowly 8bit
binary number.




How
to Read a Binary Number


As stated
previously, a byte consists of 8 bits, each bit having the possible
value of either a 1 or a 0. Now when deciphering binary numbers, don't
think of the 1 or 0 as an actual value itself, but a flag to determine
whether it has any importance in the calculation of the final result.
Lost? Let's look at an example:
Example
binary number: 10001010
Binary representation
of decimal 138.
Any time
you're going to interpret a binary number, set something up on a piece
of paper that looks like this
128

64

32

16

8

4

2

1

1

0

0

0

1

0

1

0

Now, look
at those numbers above the boxes with the red 1s and 0s. Those are decimal
numbers representing powers of 2. Starting from the left and going to
the right they are 2 to the 7th power (2^7), 2 to the 6th power (2^6),
2 to the 5th power (2^5), 2 to the 4th power (2^4), 2 to the 3rd power
(2^3), 2 to the 2nd power (2^2), 2 to the 1st power (2^1) and 2 to the
0th power (2^0):
2^7 2^6 2^5 2^4
2^3 2^2 2^1 2^0
It just so happens that with powers of 2, each successive number is double the one before it. In other words if 2^0 is equal to 1 then 2^1 = 2 and
2^2 = 4 and 2^3 = 8 and so on. Here are the values of the powers of 2 going from 2^7 down to 2^0:
128
64 32 16 8 4 2 1
These are the values that are above the boxes. Now the actual binary number
itself consists of 1s and 0s in the blue boxes which somehow magically
represents the decimal number 138. How do we get 138 from 10001010? In
the binary number when you see a 1, multiply that 1 times the value that
is directly over it. Where you see a 0 in the box, just ignore it. So
looking at our graphic again,
128

64

32

16

8

4

2

1

1

0

0

0

1

0

1

0

we see
that there is a 1 under the 128, a 1 under the 8, and a 1 under the
2. If we add only those numbers which have a binary 1 in the box under
them, we come up with 128+8+2 which equals 138.
Here's
another example:
128

64

32

16

8

4

2

1

1

1

1

0

0

1

1

0

Thus, binary
11100110 is equal to 128+64+32+4+2 which is decimal 230
And another
one:
128

64

32

16

8

4

2

1

1

0

0

0

0

0

0

1

Thus, binary
10000001 is equal to 128+1 which is decimal 129.
Hope this
makes more sense than when you started. Be sure to check out the section
on Binary Finger Counting to learn how to count to 31 on one hand. See
ya!
CLICK
[HERE] To Start Counting In Binary on Your
Fingers!






