BINARY 101 - The Simple Secrets of Computing
© 1999 Kevin
KG Computer Services - Home
What does 10 + 10 equal?
The answer, for a computer, is: 10 + 10 = 100. This expression is in
binary notation, but you could easily mistake it for
typical decimal numbers. It looks like it says "ten plus ten",
but that is due to our conditioning. 10 + 10 really equals
20,
from our human point of view. But for a computer, 10 +
10 equals 100, and 10 does not mean "ten", it means "one,
zero", and 100 does not mean one hundred, it means "one, zero,
zero". Binary is just a pattern of ones and zeros.
How many fingers do you have?
The binary number system uses only two digits, 1 (one) and 0 (zero). The decimal number
system, which we are all accustomed to, uses ten. Do you think it may have something to do with the number
of digits on your hands? It very well may. Binary numbers are best used by computers;
and decimal numbers are well known by humans. For every decimal number we can
think of, there is a corresponding binary representation in the form of a
pattern of 1's and 0's. A computer does
not store 2 as "2", it stores it as a pattern of 1's and 0's.
For example, decimal 4 is 100 in binary.
Take a look at the first sixteen binary numbers translated into their decimal counterparts:
Binary |
Decimal |
0000 |
0 |
0001 |
1 |
0010 | 2 |
0011 | 3 |
0100 | 4 |
0101 |
5 |
0110 |
6 |
0111 |
7 |
1000 |
8 |
1001 |
9 |
1010 |
10 |
1011 |
11 |
1100 |
12 |
1101 |
13 |
1110 |
14 |
1111 |
15 |
Binary Means Two
Binary is a very simple and natural number system. It is so
natural that if you look deep enough you will see it at work in nature itself.
Binary means two. Two things of opposite value. Human binary concepts consist
of things such as YES and NO, ON and OFF, LIGHT and DARK... LEFT and RIGHT, UP
and DOWN, SOMETHING or NOTHING, and so forth. Binary is so simple that it is
elegant. You would not normally think of a computer or a number system as elegant,
but when you see how it works, by your own observations, you will be quite amazed.
You would think that the decimal number system with it's ten digits, 0,1,2,3,4,5,6,7,8 and 9, would be more complicated or more difficult than a number system based on only two digits, wouldn't you? Well it is. And since you already know decimal, do you think it will be difficult to learn binary? No, it will be easy!
Mastering the binary number system is the foundation to mastering all other fields of the computer.
The Two Digits of Binary
0 (zero) and 1 (one) are the only digits that are used to
express binary numbers. You can symbolize or substitute pairs of opposites with the
numbers 0 and 1. YES is 1, NO is 0, ON is 1, OFF is 0, etc.
A computer, and its various components, can only really remember two possible values: 1 and 0, or ON and OFF.
Why is binary so natural for a computer? Because a computer runs on electricity, and in the most fundamental state, electricity can be in two states: ON or OFF. What a perfect match. We will not go into the details here, but it is good to know that the microchips, which are the "brains" of computers, are designed to handle ON and OFF states of electricity with great speed and complexity. It is essential to keep in mind that all a computer is doing, at the most basic level, is simply controlling ON and OFF pulses of electricity.
Zero or "OFF" is considered a real and significant value in computing, for it is 50% of the binary number system! The other half being 1 or "ON".
There are other number systems used in computers, besides binary. They are called hexadecimal and octal, but are not at the innermost functioning of the computer, like binary is. You could say that binary is the source of all other number systems, since it is the simplest one and uses the least amount of digits. Hexadecimal uses 16 digits and octal uses 8. We will get into these a later though; they are not as elegant or simple as binary.
0 and 1 in binary look no different than 0 and 1 in the decimal number system. 0 and 1 are found in all number systems and mean the same thing, as long as they are in position zero.
Position is everything
Number Representation | ||||||||
Digit columns: |
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Here is what binary 101 (decimal 5) looks like | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
This is decimal one hundred and one | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
Decimal number 5 (101 binary) | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 |
How 111 (decimal 7) looks in Binary | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
This is what decimal 10 looks like in Hexadecimal | 0 | 0 | 0 | 0 | 0 | 0 | 0 | A |
The digits in column 0 have the least significant value. As you move to the left, into positions 1, 2, 3, and so on, the value of the column increases. For example, if there is a decimal number 7 in position 2 and 0 in columns 1 and 0, we have the number seven hundred (700). It is much higher in value than if the 7 were in position 1, which would be seventy (70). Likewise, the same rules apply to binary numbers.
With binary we use only digits 0 and 1, and with decimal we use 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
The Digits of Four Number Systems |
||||||||||||||||
2 digits used in Binary | 1 | 0 | ||||||||||||||
10 digits used in Decimal | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||||||
16 digits used in Hexadecimal | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
8 digits used in Octal | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Base 2
Binary is the base 2 number system, decimal is the base 10 number
system, hexadecimal is base 16, and Octal is base 8. The word "base" has to do with
exponential powers, as we will see. We will be concentrating on the binary
number system.
Bits, Bytes and Nibbles
A byte is eight consecutive bits next to each other. A bit is
nothing more than a place in which one of two possible values can be stored: 0 or 1,
the two digits of binary- the two fundamental states of the computer: ON and
OFF. So a bit is either a 0 or a 1 stored in one of the positions in a
byte, as shown above. A byte is nothing
more than eight columns filled with 1's or
0's.
A nibble is half a byte, consisting of only the first four bit positions. A perfect example of nibbles are shown in the binary and decimal equivalent table above. Why use bytes and nibbles? A byte can store a pattern of eight bits of 0's and 1's, while a nibble can store four bits. It is a matter of convenience to the computer, and the human beings that interact with computers, that a byte is made up of eight bits.
There are 256 possible patterns that you can compose within eight columns of bits, from 00000000 to 11111111. It just so happens that 256 easily covers the number of keys on the computer keyboard, including the alphabet and the decimal numbers 0 through 9, along with some symbols, such as ! and $. So you can now think of a byte as a keystroke on the computer. Each key you press that shows up on your screen is really just a byte. To learn about the origin of the term Byte, follow this link.
A nibble, which can hold between 0000 and 1111 (a maximum of 16 possible values) and is mostly used with the hexadecimal number system, which we have not covered yet.
Just as each decimal number 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 have a corresponding binary representation, so does each letter in the alphabet. Let's see what the binary numbers are for the word "DOG".
DOG | |||||||||
Binary |
Decimal | ||||||||
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | D | 68 |
0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | O | 79 |
0 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | G | 71 |
Translating Binary to Decimal
Why does the binary pattern 101 equal to decimal
5? This is a question
of power and position. The power of 2, and the 8
possible bit positions in a byte.
The pattern 101, in terms of a byte, is really 00000101, with five leading zeros. If we take away the five leading zeros, the number is still equal to 5.
All leading zeros in any number system are considered insignificant. Leading zeros do not count.
So lets work with a nibble, so it looks like this: 0101, which is easier to read, since there are less zeros.
Raising binary 101 by the power of 1's positions
Binary 101 | |||||||||
Bit Column Positions |
|||||||||
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
0 | 1 | 0 | 1 | = | 5 | ||||
2^{2} | + | 2^{0} | = | 5 |
Why raise binary 101 by the power of the position of the 1's? So we humans can understand the pattern in terms of decimal. Don't worry, there is a much simpler shortcut way of translating binary to decimal and we will see how later. First, I want to show you this power raising.
We are raising 2 (since binary is based on 2) by the positions that have a 1 in them, and we do nothing with 0.
Notice that in the table above, we do not do anything with the 0's. We only look in the columns that have a 1 in them. For column 2, we see a 1 below it, so we raise 2 to the power of it's position, which is 2, and we get: 2^{2 = }(2 x 2) = 4.
For column 0, we also see a 1 below it, so 2 to the power of 0 is 1. In fact, any number to the power of 0 is always 1. Why? I will leave that to the mathematician's.
When you are done raising 2 to the power of the position of the 1's, you can add up the decimal results to get the final answer. In the example above, 101 binary is equal to 4 + 1 = 5.
The easy way to translate binary to decimal
...more to come
Binary 101 | |||||||||
Bit Columns Raised |
|||||||||
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | ||
0 | 1 | 0 | 1 | = | 5 | ||||
4 | + | 1 | = | 5 |
ASCII (American Standard Code for Information Interchange)
more to come..
Link to ASCII
Web Site
Y2K
You will come to appreciate the Year 2000 computer dilemma when you learn
how computers use binary numbers.
Reference Links
Free Online Dictionary of Computing
http://mechatronics.me.vt.edu/book/contents.html
http://cs.fit.edu/~ryan/glossary.html
Internal Notes:
1 1 0 1 (4-bits)
1 x 2^{3} + 1 x 2^{2} + 0 x 2^{1} + 1 x 2^{0}
8 + 4 + 0 + 1 = 13
5 x 16^{1} + D x 16^{0}
5 + 13 = 93_{10}
or
0101 1101
0 x 2^{7} + 1 x 2^{6} + 0 x 2^{5} + 1 x 2^{4} + 1 x 2^{3} + 1 x 2^{2} + 0 x 2^{1} + 1 x 2^{0}
0 + 64 + 0 + 16 + 8 + 4 + 0 + 1 = 93_{10}
100 = 4, and it takes up 3 bits... the preceding five bits are blank or 0 and do not have to be written as such here, but when stored in a computer, the first 5 bits are 0 and must be there. It looks like this in a computer memory: 00000100.
101 binary = 5 decimal.
Getting the binary number system down pat is the most important key to understanding the secrets of computers.
A DWORD thus is a DOUBLE WORD... A WORD is two bytes together... A WORD thus can have 256*256 possible numbers = 65535 decimal values... Double that and you get 4 bytes... which has the ability to contain 256 to the power of 4 values... which is something like 4 billion.... A DWORD is nothing but 4 bytes next to each other in memory... then we get into low byte/hi byte order... which is another story but not so important unless you learn machine language... machine language can also help one understand the underlying secrets of computers, but is not as important as knowing binary and hex numbers and how they are stored and used in the computer.
How to convert a binary byte to decimal...
eight bits of zero 00000000 = 0 and that's easy!
00000001 = 1, the same as decimal!
00000010 = 2, now you get confused!
So now you need some power... The power of two.
Each bit has a position starting from the right to the left and
with 0:
7 6 5 4 3 2 1 0 (bit position)
0 0 0 0 0 0 1 0 (the byte being interpreted)
Now take the first 1 that appears in the byte, starting from the right. There is only one in the example above.
2 to the power of that bit position of 1 is 2 because any number to the power of 1 is always going to equal itself.
Now, since all other bit positions are zero, you have nothing to do but look at the answer from above, it is 2.
Lets do binary 11.
7 6 5 4 3 2 1 0 (bit position)
0 0 0 0 0 0 1 1 (the byte being interpreted)
The first 1 in bit position 0 does not get raised to the power of 2, because 0 to the power of 2 is always 1. So now hold onto the 1 and set it aside.
The second 1 in position 1 means we do the same thing as we did
above, we raise the bit position 1 to the power of 2, and we get decimal 2. Set 2
aside.
Now that all other positions have a zero underneath them, we are done with the power phase. Now comes the add phase.
Take all the decimal number results you set aside from the power phase and add them up using regular decimal math. In this example we get 1+2= 3, and therefore 11 binary equals 3 decimal.
Lets do binary 111.
7 6 5 4 3 2 1 0 (bit position)
0 0 0 0 0 1 1 1 (the byte being interpreted)
Well, already you know that 11 = 3, so skip the first two bits. Now set the 3 aside.
Take the fourth bit position of 2, and since it has a 1 under it, we must raise the position (2) to the power of 2, which is 2*2 = 4.
Now, add 3 and 4, and you get 7. Binary 111 equals decimal 7.
HEXADECIMAL:
... hence you see things like 1F, AD, 1A, etc... A = 10 decimal, B = 11, C=12... and up to
F which is 15. Hex is used because you can fit up to 255 numbers into two
digits. FF = 255. It just so happens that 8 bits of 1's or 0's lined up next
to each other can represent up to 255 numbers...