GCSE Computing/Computing hardware/Introduction to Binary Logic/Binary logic

From Wikibooks, open books for an open world
Jump to: navigation, search

What you need to know[edit]

The exam board say that you must be able to explain "why data is represented in computer systems in binary form?".

Introduction[edit]

We are all used to counting in tens, and there being only ten different digits (0,1,2,3,4,5,6,7,8,9). when we want to go above 9 we have no problem in sticking two digits together - for example a 1 and a 0 making 10. We understand that the "1" in fact means "one lot of ten". We can do this for pretty much any number, knowing that 8,456 means "eight lots of a thousand, four lots of a hundred, five tens and six units".

Using tens like this is called "Base 10", and arose as we have ten fingers so it is easy to count like this - it's just a convenient way of doing things. Since computers don't have fingers, Base 10 is not very convenient for them. For them the best system is what is called "Base 2" or "Binary". The equivalent of fingers is detecting the amount of electricity going through a wire. For simplicity we think of the electricity as being "on" or "off". If electricity is off we call it a zero, if it is on we call it a 1. Note

One wire can tell us just if something is on or off, which isn't very useful. Suppose we have three wires together, and we (or rather the computer) checks each wire to see if it is on or off. We get the following possibilities:

Figure 1
Status Wire 1 Wire 2 Wire 3
Current? Off Off Off
Current? Off Off On
Current? Off On Off
Current? On Off Off
Current? On Off On
Current? On On Off
Current? On Off On
Current? On On Off

If we think of "Off" as zero and On as One we get

Figure 2
Status Wire 1 Wire 2 Wire 3
Current? 0 0 0
Current? 0 0 1
Current? 0 1 0
Current? 1 0 0
Current? 1 0 1
Current? 1 0 1
Current? 1 1 0
Current? 1 1 1

Now let's go back to ordinary Base 10. we have column headings like this:

Figure 3
Hundreds Tens Units Meaning
8 3 2 Eight hundreds, 3 tens and two units - 832
4 0 5 Four hundreds, zero tens and 5 units - 405

we can do the same in Binary but the column headings change

Figure 4
Sixteens Eights Fours Twos Units Meaning
1 0 1 1 0 16 + 4 + 2 = 22
0 0 0 1 1 2 + 1 = 3
1 0 0 0 1 16 + 1 = 17

The column headings are different, but the idea is the same: the column heading tells you how much an entry in that column is worth. In normal base 10, anything in the second column (from the right) is worth 10, in binary it is worth 2. The next column is worth 100 in Base 10, but only 4 in Binary.

No we can look again at Figure One or Figure Two, and say that the way those wires are on or off can tell us a number. So if the wire on the left is off, and the next two are on the "value" is 3. Figure 6 below may help you understand this.


Figure 6
Status Wire 1 Wire 2 Wire 3
Current? O O O No fours, no two's, no units = 0
Current? O 0 1 No fours, no two's, one unit = 1
Current? 0 1 0 No fours, one two, no units = 2
Current? 0 1 1 No fours, one two, one unit = 3
Current? 1 0 0 One four, no two's, no units = 4
Current? 1 0 1 One four, no two's, one units = 5
Current? 1 1 0 One four, One two, no units = 6
Current? 1 1 1 One four, One two, One unit = 7

Exercise[edit]

Practice this idea at http://forums.cisco.com/CertCom/game/binary_game_page.htm

The maths and logic of it[edit]

Base 10 (ordinary maths) evolved because we have ten fingers and it is easy to think of ten digits (0 to 9)

Base 2 (Binary) is useful because computers can only really record two possibilities: on or off. So they use 0 and 1 for these. Therefore, base 2 does not have the digits 2 to 9. They are NEVER used.. This is exactly the same as there not being a special digit for eleven in Base 10: you just use to 1's. To make three in Base 2, use two 1's, meaning one lot of two, and one lot of one = 3

If you are happy with maths ...[edit]

(If not, see below!)

Each column goes up by a power, as follows: Base 10

10^5 10^4 10^3 10^2 10^1 10^0
100,000 10,000 1000 100 10 1

Base 2

2^5 2^4 2^3 2^2 2^1 2^0
32 16 8 4 2 1

If you are not so happy with maths ...[edit]

In normal base 10 each column is TEN TIMES the column to its right.
In Base 2 (Binary) each column is DOUBLE the one to its right.

Next[edit]

Bits, Bytes, Nibbles