52905.fb2
Unlike us, microprocessors have not grown up with the idea that 10 is a convenient number of digits to use. We have taken it so much for granted that we have even used the word digit to mean both a finger and a number.
Microprocessors and other digital circuits use only two digits – 0 and 1 – but why? Ideally, we would like our microprocessors to do everything at infinite speed and never make a mistake. Error free or high speed – which would you feel is the more important?
It’s your choice but I would go for error free every time, particularly when driving my car with its engine management computer or when coming in to land in a fly-by-wire aircraft. I think most people would agree.
So let’s start by having a look at one effect of persuading microprocessors to count in our way.
If the input of a microprocessor is held at a constant voltage, say 4 V, this would appear as in Figure 2.1.
Figure 2.1 A constant voltage
If we try to do this in practice, then careful measurements would show that the voltage is not of constant value but is continuously wandering above and below the mean level. These random fluctuations are called electrical noise and degrade the performance of every electronic circuit. We can take steps to reduce the effects but preventing it altogether is, so far, totally impossible. We can see the effect by disconnecting the antenna of our television. The noise causes random speckles on the screen which we call snow. The same effect causes an audible hiss from the loudspeaker. The effect of noise is shown in Figure 2.2.
Figure 2.2 A ‘noisy’ voltage
Most microprocessors use a power supply of 5 V or 3.3 V. To keep the arithmetic easy, we will assume a 5 V system.
If we are going to persuade the microprocessor to count from 0 to 9, as we do, using voltages available on a 5 V supply would give 0.5 V per digit:
0 = 0 V
1 = 0.5 V
2 = 1 V
3 = 1.5 V
4 = 2 V
5 = 2.5 V
6 = 3 V
7 = 3.5 V
8 = 4 V
9 = 4.5 V
If we were to instruct our microprocessor to perform the task 4 + 4 = 8, by pressing the ‘4’ key we could generate a 2 V signal which is then remembered by the microprocessor. The + key would tell it to add and pressing the ‘4’ key again would then generate another 2 V signal.
So, inside the microprocessor we would see it add the 2 V and then another 2 V and, hence, get a total of 4 V. The microprocessor could then use the list shown to convert the total voltage to the required numerical result of 8. This simple addition is shown in Figure 2.3.
Figure 2.3 It works! 4 + 4 does equal 8
This seemed to work nicely – but we ignored the effect of noise. Figure 2.4 shows what could happen. The exact voltage memorized by the microprocessor would be a matter of chance. The first time we pressed key 4, the voltage just happened to be at 1.5 V but the second time we were luckier and the voltage was at the correct value of 2 V.
Figure 2.4 Noise can cause problems
Inside the microprocessor:
1.5 V + 2 V = 3.5 V
and using the table, the 3.5 V is then converted to the number 7. So our microprocessor reckons that 4 + 4 = 7.5!
Since the noise is random, it is possible, of course, to get a final result that is too low, too high or even correct.
Sorry, just dreaming. There isn’t one. The small particle-like components of electricity, called electrons, vibrate in a random fashion powered by the surrounding heat energy. In conductors, electrons are very mobile and carry a type of electrical charge that we have termed negative. The resulting negative charge is balanced out by an equal number of fixed particles called protons, which carry a positive charge (see Figure 2.5).
Figure 2.5 Equal charges result in no overall voltage
The overall effect of the electron mobility is similar to the random surges that occur in a large crowd of people jostling around waiting to enter the stadium for the Big Match. If, at a particular time, there happens to be more electrons or negative charges moving towards the left-hand end of a piece of material then that end would become more negative, as shown in Figure 2.6. A moment later, the opposite result may occur and the end would become more positive (Figure 2.7). These effects give rise to small random voltages in any conductor, as we have seen.
Figure 2.6 A random voltage has been generated
Figure 2.7 The opposite effect is equally likely
The higher the temperature, the more mobile the electrons, the greater the random voltages and the more electrical noise is present. A solution:
High temperature = high noise
so:
Low temperature = low noise.
Put the whole system into a very cold environment by dropping it in liquid nitrogen (about –200°C) or taking it into space where the ‘shade’ temperature is about –269°C. The cold of space has created very pleasant low noise conditions for the circuits in space like the Hubble telescope. On Earth most microprocessors operate at room temperature. It would be inconvenient, not to mention expensive, to surround all our microprocessor circuits by liquid nitrogen. And even if we did, there is another problem queuing up to take its place.
Let’s return to the Big Match. Two doors finally open and the fans pour through the turnstiles. Now we may expect an equal number of people to pass through the two entrances as shown in Figure 2.8 but in reality this will not happen. Someone will have trouble finding their ticket; friends will wait for each other; cash will be offered instead of a ticket; someone will try to get back out through the gate to reach another section of the stadium. As we can imagine, the streams of people may be equal over an hour but second by second random fluctuations will occur.
Figure 2.8 The fans enter the stadium
Electrons don’t lose their tickets but random effects like temperature, voltage and interactions between adjacent electrons have a very similar effect.
A single current of, say, 1 A can be split into two currents of 0.5 A when measured over the long-term, but when examined carefully, each will contain random fluctuations. This type of electrical noise is called partition noise or partition effect. The overall effect is similar to the thermal noise and, between them, would cause too much noise and hence would rule out the use of a 10-digit system.
The 10-finger system that we use is called a ‘denary’ or ‘decimal’ system. We have seen that a 5 V supply would accommodate a 10-digit counting system if each digit was separated by 0.5 V or, using the more modern choice of 3.3 V, the digits would be separated by only 0.33 V.
Question: Using a 5 V supply and a denary system, what is the highest noise voltage that can be tolerated?
Answer: Each digit is separated by only 5 V/10 = 0.5 V. The number 6 for example would have a value of 3 V and the number 7 would be represented by 3.5 V. If the noise voltage were to increase the 3 V to over 3.25 V, the number is likely to be misread as 7. The highest acceptable noise level would therefore be 0.25 V. This is not very high and errors would be common. If we used a supply voltage of 3.3 V, the situation would get even worse.
So why don’t we just increase the operating voltage to say, 10 V, or 100 V? The higher the supply voltage the less likely it is that electrical noise would be a problem. This is true but the effect of increasing the supply would be to require thicker insulation and would increase the physical size of the microprocessor and reduce its speed. More about this in Chapter 11.
If we reduce the number of digits then a wider voltage range can be used for each value and the errors due to noise are likely to occur less often.
We have chosen to use only two digits, 0 and 1, to provide the maximum degree of reliability. A further improvement is to provide a safety zone between each voltage. Instead of taking our supply voltage of 3.3 V and simply using the lower half to represent the digit 0 and the top half for 1, we allocate only the lower third to 0 and the upper third to 1 as shown in Figure 2.9. This means that the noise level will have to be at least 1.1 V (one-third of 3.3 V) to push a level 0 digit up to the minimum value for a level 1.
Figure 2.9 A better choice of voltages
Normally, we count in the system we call ‘denary’. We start with 0
then go to 1 then to a new symbol that we write as 2 and call ‘two’. This continues until we run out of symbols. So far, it looks like this:
0
1
2
3
4
5
6
7
8
9
At this point we have used all the symbols once and, to show this, we put a ‘1’ to the left of the numbers as we re-use them. This gives us:
10
11
12
13
14
… and so on up to 19 when we put a 2 on the left-hand side and start again 20, 21, 22 etc.
When we reach 99, we again add a ‘1’ on the left-hand side and put the other digits back to zero to give 100. After we reach 999, we go to 1000 and so on.
Counting is not easy. We often take it for granted but if we think back to our early days at school, it took the teacher over a year before we were happy and reasonably competent. So counting is more difficult than microprocessors – you’ve mastered the difficult part already!
The base of a number system is the number of different symbols used in it. In the case of the denary system, we use 10 different symbols, 0…9, other numbers, like 28 657, are simply combinations of the 10 basic symbols.
Since the denary system uses 10 digits, the system is said to have a base of 10. The base is therefore just the technical word for the number of digits used in any counting system.
We can count using any base that we like. In the denary or decimal system, we used a base of 10 but we have seen that microprocessors use a base of 2 – just the two digits 0 and 1. This is called the binary system.
We usually abbreviate the words BInary digiT to bit. Counting follows the same pattern as we have seen in the denary system: we use up the digits then start again. Let’s give it a try. Start by listing all the digits:
0
1
and that’s it!
We now put a ‘1’ in the next column and start again:
10
11
It is convenient at this stage to keep the number of binary columns the same and so we add a 0 at the start of the first two digits. These extra zeros do not alter the value at all. For example, the denary number 25 is not affected by writing it as 025 or 0025 or even 000 000 000 000 025.
The binary and decimal equivalents are:
Binary | Denary |
---|---|
00 | 0 |
01 | 1 |
10 | 2 |
11 | 3 |
We do the same again – put a ‘1’ in the next column and repeat the pattern to give:
Binary | Denary |
---|---|
100 | 4 |
101 | 5 |
110 | 6 |
111 | 7 |
and once more:
Binary | Denary |
---|---|
1000 | 8 |
1001 | 9 |
1010 | 10 |
1011 | 11 |
Here is a number: 1000. But what number is it? Is it a thousand in denary or is it eight written in binary?
I don’t know. I could take a guess but the difference between flying an aircraft at eight feet and a thousand feet is a serious matter. The only way to be certain is to say so at the time. This is done by showing the base of the number system being used to make the meaning quite clear. The base of the number system is shown as a subscript after the number.
If the 1000 were a binary number, it is written as 10002 and if it were a denary number it would be shown as 100010.
It would be easy to advise that the base of the number system in use is always shown against every number but this would be totally unrealistic. No one is going to write a base after their telephone number or a price in a shop. Use a base when it would be useful to avoid confusion, such as by writing statements like 1000 = 8 (a thousand = eight???). Write it as 10002 = 810 and make life a little easier.
Of course, if someone were to ask us for the binary equivalent of nine we could just start from zero and count up until we reach nine. This is a boring way to do it and with larger numbers like 1 000 00010 it would be very tedious indeed. Here is a better way. The method will be explained using the conversion of 5210 to binary as an example.
A worked example
Convert 5210 to binary
Step 1: Write down the number to be converted
52
Step 2: Divide it by 2 (because 2 is the base of the binary system), write the whole number part of the answer underneath and the remainder 0 or 1 alongside
52
26 0
Step 3: Divide the answer (26) by 2 and record the remainder (0) as before
52
26 0
13 0
Step 4: Divide the 13 by 2 and write down the answer (6) and the remainder (1)
52
26 0
13 0
6 1
Step 5: 2 into 6 goes 3 remainder 0
52
26 0
13 0
6 1
3 0
Step 6: Dividing 3 gives an answer of 1 and a remainder of 1
52
26 0
13 0
6 1
3 0
1 1
Step 7: Finally, dividing the 1 by 2 will give 0 and a remainder of 1
52
26 0
13 0
6 1
3 0
1 1
0 1
Step 8: We cannot go any further with the divisions because all the answers will be zero from now on. The binary number now appears in the remainder column. To get the answer read the remainder column from the bottom UPWARDS
52
26 0 = 1101002
13 0 ↑
6 1 ↑
3 0 ↑
1 1
0 1
Method
1 Divide the denary number by 2 – write the whole number result underneath and the remainder in a column to the right.
2 Repeat the process until the number is reduced to zero.
3 The binary number is found by reading the remainder column from the bottom upwards.
Another example
Here is one for you to try. If you get stuck, the solution is given below. Convert 218710 to a binary number
2187
1093 1 = 1000100010112
546 1 ↑
273 0 ↑
136 1 ↑
68 0 ↑
34 0
17 0
8 1
4 0
2 0
1 0
0 1
Doing it by calculator: Many scientific calculators can do the conversion of denary to binary for us. Unfortunately, they are limited to quite low numbers by the number of digits able to be seen on the screen. To do a conversion, we need:
1 A scientific calculator that can handle different number bases.
2 The instruction booklet.
3 About half an hour to spare – or a week if you have lost the instructions.
The exact method varies but on my elderly Casio it goes something like this:
To tell the calculator that the answer has to be in binary I have to press mode mode 3 then the ‘binary’ key.
It now has to be told that the input number is decimal. This is the exciting key sequence logic logic logic 1 now just put in our number 52 and press the = key and out will pop the answer 110100.
If we look at a denary number like 8328, we see that it contains two eights. Now these two figures look identical however closely we examine them, but we know that they are different. The 8 on the right-hand end is really 8 but the other one is actually 8000 because it is in the thousands column.
The real value of a digit is dependent on two things: the digit used and the column in which it is placed.
In the denary system, the columns, starting from the right, are units, tens, hundreds, thousands etc. Rather than use these words, we could express them in powers of ten. A thousand is 10×10×10=10³ and in a similar way, a hundred is 10², ten is 10¹ and a unit is 100. Each column simply increases the power applied to the base of the number system. Columns in a binary world also use the base raised to increasing powers as we move across the columns towards the left. So we have:
2³ 2² 2¹ 20
The denary equivalent can be found by multiplying out the powers of two. So 2³ is 2×2×2 = 8 and 2²=4, 2¹=2 and finally 20=1. Starting from the right-hand side, the column values would be 1, 2, 4, 8 etc. Let’s use this to convert the binary number 1001 into denary.
Method
Step 1: Write down the values of the columns
8 4 2 1
Step 2: Write the binary number underneath
8 4 2 1
1 0 0 1
Step 3: Evaluate the values of the columns
8 × 1 = 8
4 × 0 = 0
2 × 0 = 0
1 × 1 = 1
Step 4: Add up the values
8 + 1 = 9
As we have seen, all the columns containing a binary 0 can be ignored because they always come out to 0 so a quicker way is to simply add up all the column values where the binary digit is 1.
Method
1 Write down the column values for the binary system using the same number of columns as are shown in the binary number.
2 Enter the binary number, one bit under each column heading.
3 Add the values of each column where a 1 appears in the binary number. Calculator note: This is much the same as we saw the previous conversion. To tell the calculator that the answer has to be in decimal I have to press mode mode 3 then the ‘decimal’ key.
It now has to be told that the input number is binary. This is done by the key sequence logic logic logic 3 now just put in our binary number 1001 and press the = key and out will pop the answer 9.
Another example
Once again, here is one for you to try. If you have problems, the answer follows.
Convert 1011001012 to a denary number
Step 1: Write down the column values by starting with a 1 on the right-hand side then just keep doubling as necessary
28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
---|---|---|---|---|---|---|---|---|
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Step 2: Enter the binary number under the column headings
256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|---|
1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
Step 3: Add up all the column values where the binary digit is 1
256 + 64 + 32 + 4 + 1 = 357
So, 1011001012 = 35710 or just 357 since denary can be assumed in this case.
All the information entering or leaving a microprocessor is in the form of a binary signal, a voltage switching between the two bit levels 0 and 1. Bits are passed through the microprocessor at very high speed and in large numbers and we find it easier to group them together.
Nibble
A group of four bits handled as a single lump. It is half a byte.
Byte
A byte is simply a collection of 8 bits. Whether they are ones or zeros or what their purpose is does not matter.
Word
A number of bits can be collected together to form a ‘word’. Unlike a byte, a word does not have a fixed number of bits in it. The length of the word or the number of bits in the word depends on the microprocessor being used.
If the microprocessor accepts binary data in groups of 32 at a time then the word in this context would include 32 bits. If a different microprocessor used data in smaller handfuls, say 16 at a time, then the word would have a value of 16 bits. The word is unusual in this context in as much as its size or length will vary according to the situations in which it is discussed. The most likely values are 8, 16, 32 and 64 bits but no value is excluded.
Long word
In some microprocessors where a word is taken to mean say 16 bits, a long word would mean a group of twice the normal length, in this case 32 bits.
Kilobyte (Kb or KB or kbyte)
A kilobyte is 1024 or 210 bytes. In normal use, kilo means 1000 so a kilovolt or kV is exactly 1000 volts. In the binary system, the nearest column value to 1000 is 1024 since 29=512 and 210=1024. The difference between 1000 and 1024 is fairly slight when we have only 1 or 2 Kb and the difference is easily ignored. However, as the numbers increase, so does the difference. The actual number of bytes in 42 Kb is actually 43 008 bytes (42×1024). The move in the computing world to use an upper case K to mean 1024 rather than k for meaning 1000 is trying to address this problem.
Unfortunately, even the upper or lower case b is not standardized so tread warily and look for clues to discover which value is being used. If in doubt use 1024 if it is to do with microprocessors or computers. Bits often help to confuse the situation even further. 1000 bits is a kilobit or kb. Sometimes 1024 bits is a Kb. One way to solve the bit/byte problem is to use kbit (or Kbit) and kbyte (or Kbyte).
Megabyte (MB or Mb)
This is a kilokilobyte or 1024×1024 bytes. Numerically this is 220 or 1 048 576 bytes. Be careful not to confuse this with mega as in megavolts (MV) which is exactly one million (106).
Gigabyte (Gb)
This is 1024 megabytes which is 230 or 1 073 741 824 bytes. In general engineering, giga means one thousand million (109).
Terabyte (TB or Tb)
Terabyte is a megamegabyte or 240 or 1 099 511 600 000 bytes (Tera = 1012).
Petabyte (PB or Pb)
This is a thousand (or 1024) times larger than the Terabyte so it is 1015 in round numbers or 240 which is pretty big. If you are really interested, you can multiply it out yourself by multiplying the TB figure by 1024.
In each case, choose the best option.
1 Typical operating voltages of microprocessors are:
(a) 0 V and 1 V.
(b) 3.3 V and 5 V.
(c) 220 V
(d) 1024 V.
2 The most mobile electrical charge is called:
(a) a proton and has a positive charge.
(b) a voltage and is always at one end of a conductor.
(c) an electron and has a negative charge.
(d) an electron and has a positive charge.
3 The denary number 600 is equivalent to the binary number:
(a) 1001011000.
(b) 011000000000.
(c) 1101001.
(d) 1010110000.
4 When converted to a denary number, the binary number 110101110:
(a) will end with a 0.
(b) must be greater than 256 but less than 512.
(c) will have a base of 2.
(d) will equal 656.
5 A byte:
(a) is either 1024 or 1000 bits.
(b) is simply a collection of 16 bits.
(c) can vary in length according to the microprocessor used.
(d) can have the same number of bits as a word.