# Binary Arithmetic

The following table attempts to make correspondences between conventions for defining binary logic states. In the case of the TTL logic gates we will be using in the lab, the Low voltage state is roughly 0-1 Volt and the High state is roughly 2.5-5 Volts. See page 475 of the text for the exact conventions for TTL as well as other hardware gate technologies.

The convention for naming these states is illustrated in Fig. 1. The "positive true" case is illustrated. The relationship between the logic state and label (in this case "switch open") at some point in the circuit can be summarized with the following:

Boolean Logic Boolean Algebra Voltage State
(positive true)
Voltage State
(negative true )
True (T) 1 High (H) Low (L)
False (F) 0 L H

The labelled voltage is High (Low) when the label's stated function is True (False). In the figure, the stated function is certainly true (switch open), and this does correspond to a high voltage at the labelled point. (Recall that with the switch open, Ohm's Law implies that with zero current, the voltage deference across the "pull up" resistor is zero, so that the labelled point is at +5 Volts. With a closed switch, the labelled point is connected to ground, with a 5 Volt drop across the resistor and a current of I = V/R = 5 mA through it.)

With the convention known as "negative true", the label would be changed to "switch closed" with a bar over it: switch closed. Our statement becomes:

The labelled voltage is Low (High) when the label's stated function is True (False). So in the figure, the stated function (switch closed) is true when the voltage is low. The bar is meant to invoke the Boolean inversion operation: and so forth.

## Binary Arthematic

The most familiar is unsigned binary. An example of a 8-bit number in this case isEach digit in binary is a 0 or a 1 and is called a bit, which is an abbreviation of binary digit. There are several common conventions for representation of numbers in binary.

010011112 = 0 X 27 + 1 X 26 +.........+ 1 X 20 = 64 + 8 + 4 + 2 + 1 = 7910

(Generally the subscripts will be omitted, since it will be clear from the context.) To convert from base 10 to binary, one can use a decomposition like above, or use the following algorithm illustrated by 79:

79 / 2 = 39

Remainder 1, then

39/2 = 19

Remainder 1, and so forth. Then assemble all the remainders in reverse order.

The largest number which can be represented by n bits is 2n − 1. For example, with 4 bits the largest number is 11112 = 15.

The most significant bit (MSB) is the bit representing the highest power of 2, and the LSB represents the lowest power of 2.

Arithmetic with unsigned binary is analogous to decimal. For example 1-bit addition and multiplication are as follows:

0 + 0 = 0 0 x 0 = 0
0 + 1 = 1 0 x 1 = 0
1 + 1 = 0 1 x 1 = 1

Note that this is different from Boolean algebra,as we shall see shortly, where 1+1=1.

Another convention is called BCD ("binary coded decimal"). In this case each decimal digit is separately converted to binary. Therefore, since

7 = 01112

and

9 = 10012

then

79 = 01111001 (BCD).

Note that this is different than our previous result. We will use BCD quite often in this course. It is quite convenient, for example, when decimal numerical displays are used.

Yet another convention is Gray code. You have a homework problem to practice this.

This is less commonly used.

## Representation of Negative Numbers

There are two commonly used conventions for representing negative numbers.

With sign magnitude, the MSB is used to ﬂag a negative number. So for example with 4-bit numbers we would have

0011 = 3

and

1011 = −3.

This is simple to see, but is not good for doing arithmetic.

With 2's complement, negative numbers are designed so that the sum of a number and its 2's complement is zero. Using the 4-bit example again, we have

0101 = 5

and its 2's complement

−5 = 1011

10000 = 0

(The 5th bit doesn't count!)

Both addition and multiplication work as you would expect using 2's complement.

There are two methods for forming the 2's complement:

−5 = − 8 + 3 = 1000 + 0011 = 1011.

1. Make the transformation 0 --> 1 and 1 --> 0, then add 1.
2. Add some number to −2MSB to get the number you want. For 4-bit numbers an example of finding the 2's complement of 5 is