## Architecture 1 - Basic Concepts

**Introduction**

One of the first questions that new students always ask is, "Why do we have to learn to add and subtract numbers in binary?" Well, there is a very good reason for that, and I am about to try to demonstrate what it is. It's because, basically, computers are stupid. They can only recognise two states - which it is convenient for us to think of as being states of 1 or 0. Think of a basic light switch. It can be either on, or off...

It can't be between states, i.e. half-on, half-off...

...and the time taken, to move between being on and off, is so tiny that it doesn't count.

We therefore refer
to a computer as being a **bi-stable**,or a **two-state**, system.

Now multiply your basic switch by about 70 million... and you have a primaeval computer processor!

Very early computers worked by valve technology. A valve is simply a glorified lightbulb, which either held a current or it didn't. Nowadays, these switches are made from tiny capacitors and transistors. A capacitor, like a valve, is a component capable of holding an electrical charge; if it is charged, we think of it as being worth 1; and if it is discharged, i.e. holding no current, we think of it as being worth 0.

Our switches then move, at a very rapid speed, between 0 and 1 and back again. Because there are millions of them in a computer system, they are capable of storing and executing very complex programs.

But before we go on to study how programs are executed, we have to start off with something rather simpler... and that's how to store numbers.

** Binary
Coded Decimal (BCD)**

If you have one valve, switch or lightbulb, you can count up to 1. The switch can be OFF (0) or ON (1).

But add a second switch, and you can count up to 3 (00, 01, 10, 11). The switch on the left is worth "lots" of 1, and the one on the right is worth "lots" of 2. If both switches are on, you have a 2 and a 1, which added together, make 3.

Let's keep adding more switches to the right. With the third switch, we can now count up to 7 (4+2+1). Can you see the pattern here? The next switch will count lots of 16, then 32s. then 64s and so on.

When we reach eight
switches, or **bits**, we can count up
to 255 (128+64+32+16+8+2+1). Nowadays, the
usual term for a group of eight bits is a **byte**. The more mathematically-minded amongst you
will also have spotted that the values are incrementing by the **powers of 2**. We are actually counting in **
binary**, or **base 2**.

By extension, 16 bits (two bytes) can hold numbers up to 65 535. 24 bits can hold up to 16 777 215. 32 bits can accommodate numbers up to 4 294 967 295. And 64 bits can handle up to a whopping 18 446 744 073 709 551 616!

This may remind you of the old Chinese folk tale where the wise man outsmarts the king by asking for just one grain of rice on the first square of the chessboard. For each successive square he will get double the amount of the previous square. Although this request initially sounds meagre, the king soon discovers that he has been well and truly beaten as he tries to supply the rice for each of the 64 squares of the chessboard!

**Number Conversion - Decimal to Binary**

One of the first tasks that any student must undertake is the conversion of numbers in a **Denary (Decimal)** or **Base 10 format**, to **Binary (Base 2)**. This is actually a lot easier than it sounds. There are many excellent books and websites out there which will demonstrate various methods, the most popular amongst professionals being the "divide by 2 and note the remainders" method.

Then you take your "target" number. Let's start with 3195 as an example.

You can get 1 "lot" of 2048 out of it, leaving (3195-2048) = 1147 still to allocate between the columns. Write down a 1 under the 2048.

We are left with 1147, so we can get 1 "lot" of 1024 from that, leaving (1147-1024) = 123. Write down a 1 under 1024.

We don't have enough left to get 512, 256 or 128, so ignore those for the moment. We can, however, get 1 lot of 64.

We are now left with (123-64) = 59. Enough to make a 32, a 16 and an 8, leaving 3 over, which is fitted into 2 and 1.

Now all we have to do is put padding zeroes into the unused spaces.

*Voilá!* The number 3195 converted to binary and formatted to 12 bits!

The next thing I have to show you is how to move in the opposite direction changing binary numbers into decimal. This is just as easy! You are doing exactly the same thing, but in the opposite direction. Begin by lining up your number under the relevant columns (allow yourself plenty of space for this) -

...and add everywhere where there is a 1. So in the example above we would have 2048 + 512 + 256 + 32 + 8 + 4 + 1 = 2861. Simple!

Now that you can change binary formatted numbers to decimal and back again, you can move onto the next section, hexadecimal numbers.