Выбрать главу

Bit 0 is used to hold the sign-bit for the mantissa using the normal convention of 0 = positive and 1 = negative.

Bits 1–23 hold the mantissa in normal binary.

Bits 24–31 hold the exponent. The eight digits are used to represent numbers from –127 to +128 using either two’s complement numbers or excess-127 notation.

We have already met two’s complement numbers earlier in this chapter so we will look at excess-127 notation now.

Excess-127 notation

This is very simple, despite its impressive name. To find the exponent just add 127 to its value then convert the result to binary. This addition will ensure that all exponents have values between 0 and 255, i.e. all positive values.

Example

If the exponent is –35 then we add 127 to give the result 92, which we can then convert to binary (01011100).

When the value is to be taken out of storage and converted back to a binary number, the above process is reversed by subtracting the 127 from the exponent.

Size, accuracy and speed

The mantissa can go as high as 1.1111 1111 1111 1111 1111 1112. To the right of the binary point the decimal equivalents are values of 1.5+0.25+0.125+0.0625 etc. Adding these up gives a total that is virtually 2 – but not quite. The larger the number of bits in the mantissa, the more accuracy we can expect in the result. The exponent has eight bits so it can range from –127 to +128 giving a maximum number of 1×2128 which is approximately 3.4×1038. The accuracy is limited by the number of bits that can be stored in the mantissa, which in this case is 23 bits.

If we want to keep to a total of 32 bits, then we have a trade-off to consider. Any increase in the size of the exponent, to give us larger numbers, must be matched by reducing the number of bits in the mantissa that would have the effect of reducing the accuracy. Floating point operations per second (FLOPS) is one of the choices for measuring speed.

IBM are building (2002) a new super computer employing a million microprocessors. The Blue Gene project will result in a computer running at a speed of over a thousand million million operations per second (1 petaflop). This is a thousand times faster that the Intel 1998 world speed record or about two million times faster than the current top-of-the-range desktop computers.

Single and double precision

If we need more accuracy, an alternative method is to increase the number of bits that can be used to store the number from 32 (singleprecision) to 64 (double-precision). If this extra storage space is devoted to increasing the mantissa bits, then the accuracy is increased significantly.

Binary coded decimal (BCD)

Binary coded decimal numbers are very simple. Each decimal digit is converted to binary and written as a 4-bit or 8-bit binary number. The number 5 would be written as 01012 or 000001012. So far, this is the same as ‘ordinary’ binary but the change occurs when we have more digits.

Consider the number 2510. In regular binary this would convert to 110012. Alternatively, we could convert each digit separately to 4-bit or 8-bit numbers:

2 = 00102 or 0000 00102

5 = 01012 or 0000 01012

Putting these together, 2510 could be written using the 4-bit numbers as 0010 01012. This uses one byte and is called Packed BCD. Alternatively, we could use the 8-bit formats and express 2510 as 0000 0010 0000 01012 and would now use two bytes. This is called Unpacked BCD.

There are two disadvantages. Firstly, many numbers are of increased length after converting to BCD, particularly so if we use unpacked BCD or the numbers are very large like 25×1075. In addition, arithmetic is much more difficult although, generally, microprocessors do have the ability to handle them.

The advantage becomes apparent when the microprocessor is controlling an external device like digits on displays at a filling station or accepting inputs from a keyboard. The coding is simple and does not involve the conversion of the numbers to binary.

Overall

Arithmetic → use binary

Inputting and outputting numbers → use BCD

Quiz time 4

In each case, choose the best option.

1 The number –3510, when expressed as an 8-bit binary number in two’s complement form, is:

(a) 00100011.

(b) 1111011101.

(c) 11011101.

(d) 00110101.

2 The number 710 converted to an unpacked BCD format would be written as:

(a) 1110 0000.

(b) 7H.

(c) 0000 0111.

(d) 0111.

3 The signed magnitude number 110011002 is equivalent to:

(a) –7610.

(b) 20410.

(c) CCH.

(d) 121210.

4 In the number 0.5×1024 the number:

(a) 10 is the mantissa.

(b) 24 is the exponent.

(c) 0 is the sign bit.

(d) 5 is the radix.

5 A signed magnitude number that has a figure:

(a) zero as the msb is a negative number.

(b) one as the lsb is a negative number.

(c) one as the msb is a negative number.

(d) zero as the lsb is a negative number.

5. An introduction to logic gates and their uses

Opening and closing gates

In the last chapter the binary values zero and one are represented by two different voltages. Binary zero is a voltage close to 0 V and binary one by a voltage close to +5 V (some logic circuits use other voltage levels but this is a popular value and will serve as an example). A gate is a simple electronic circuit that has a single output voltage that corresponds to one of the two binary values. These gates are often referred to as ‘logic gates’ and the output voltages as ‘logic 0’ or ‘logic 1’ instead of binary 0 and 1. The distinction is just in the name. If you were to ask a mathematician or a computer programmer, they will refer to the outputs as binary values but an electronics engineer will call them logic levels. It really doesn’t matter.

What decides the output voltage?

We connect one or more voltages to the input of the gate. These input voltages are either logic 0 or logic 1 levels. The logic gate looks at the input voltages and ‘decides’, depending on its design, what voltage to produce at the output of the circuit.

There are only four basic designs of gate. They are called the NOT gate, the AND gate, the OR gate and the XOR gate. Notice how we use capital letters for the names of the gates otherwise we can finish up with some almost indecipherable sentences. Not not or and not and or not…

A little reminder before we start. Logic gates are clever little chaps but they are not magic. Just like any other electronic circuit, they need power supplies to make them work. Now, because all gates and microprocessors need power supplies, we tend to assume that everyone knows that. You will notice that power supplies are not shown in any of the diagrams in this chapter but that doesn’t mean that they are not there!

We will explore these gates now, starting from the simplest.

The NOT gate

It has only one input and performs a very simple function. It simply reverses the binary value. If we put a logic 1 into it, we get a logic 0 at the output. Similarly, a 0 at the input gives a 1 at the output. On a diagram, we represent a NOT gate by a symbol as shown in Figure 5.1.