Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

Binary Numbers and Gates Chapter 4

I. Binary Number System A. As a general rule, people use 10 digits to represent numbers and letters to represent textual information. 1. This works well for us, but not so good for computers. B. There are two types information representation. 1. External representation is the way we, as humans, generally represent information. Its also the way we get data into a computer via keyboard or the way data are displayed on the screen. 2. Internal representation is the way the computer stores data in memory. This is done using the binary numbering system. C. The binary number system is a base-2 system similar to the familiar base-10 system we use every day. 1. The base-10 system we use has 10 unique digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. 2. When you think about it, the value of those digits in a given number depends on the location of that digit within a given number. a. The locations represent powers of 10. b. For example, in the number 1,234, the 4 is in the ones location (or 100), the 3 is in the tens location (or 101), the 2 is in the hundreds location (or 102), and the 1 is in the thousands location (or 103). c. So, in truth, the number 1,234 could be represented like this: (1 x 103) + (2 x 102) +(3 x 101) + (4 x 100) = 1,000 + 200 + 30 + 4 = 1,234
3. The same is true for the binary number system except there are only two

unique digits: 0 and 1. a. The difference here is that the locations are represented by powers of 2 rather than powers of 10. So, the right-most slot would be 20 instead of 100. The next slot to the left would be 21 instead of 101 and so forth. b. Consider this 6-digit binary number: 110101. Using the same approach as above with the 1,234, we could represent 110101 as: (1 x 25) + (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20) c. What makes converting a binary number to a base-10 (i.e., decimal) number so easy is that 1 times anything is still the same anything and 0 times anything is always zero. So, if we carry the evaluation of the number another step, heres what we get: (1 x 25) + (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20) = 32 + 16 + 0 + 4 + 0 + 1 = 53

d. Lets do another. What is the base-10 (decimal) value of 1110111?

D. How do we convert a base-10 number to a binary number? 1. Here we have to do some division and make use of the leftovers (commonly called remainder ). 2. Suppose we want to convert 1910 to a binary number. We need to do two things. a. First we have to divide and keep track of the quotient. Remember, this is integer division. b. As we divide, we also need to keep track of the remainder. This is what will be used to create the binary number. Operation 19 / 2 9/2 4/2 2/2 1/2 Quotient 9 4 2 1 0 Stop since the last quotient was 0 Remainder 1 1 0 0 1

3.
4.

E. 1.

c. When were finished, we take the remainders and read from the bottom (last division operation) up to the top (first division operation). That gives us 10011 for the answer. Does it work? Well, try converting 10011 back to its base-10 equivalent and see what you get! Lets do another. What is the base-2 (binary) value of 135? How do we add binary numbers? Again, this is similar to doing addition in base-10. a. Consider adding 9 and 1. We all know the answer (in base-10, anyway) is 10, but lets take a closer look. b. If we align the numbers vertically, we see this: 9 1
c. If we add the 1 to the 9, we know the largest unique digit in the base-

10 system is 9, so we have to flip over to the next set of 0-9 numbers (i.e., the 101 column) and put a zero in the 100 column. carry 1 9 1 10

d. What about adding 11 and 9? 11 9 e. Again, we have a carry 1 situation, but this time the carried 1 gets added to the existing 1 in the tens column: carry 1 11 9 20 2. The same thing applies when adding binary numbers. a. Lets start with the four possible combinations of binary numbers and the rules that apply i. The first three are fairly intuitive: 0 0 0 0 1 1 1 0 1

ii. But lets look at the fourth possibility: 1 1


iii. We know that the largest unique digit in binary is 1. So, we have to do

a carry just like in the base-10 system. The difference is well be carrying into the 21 column. carry 1 01 01 10 (01 and 1 are the same)

b. Now lets do some with a few more digits.

101 010

110 101

100 101

c. Finally, lets do two that are a little more of a challenge.

10010 01011

10111 11011

II.

Reliability of Binary Representation and Binary Storage Devices A. In theory, we could have a decimal computer instead of binary. But, theoretical issues aside, theres a practical reason for using binary 1. Computers run on electricity. Long story short: Computers use electrical impulses for internal representation of information. 2. If we tried to implement a base-10 computer, wed have to have a way to use ten different voltage levels to represent the ten different unique digits associated with the base-10 number system. 3. While this is certainly doable, how reliable is it? As electrical devices age, they become less reliable and suffer from a change in energy state called drift. For example, if a device originally started out with a voltage of +40 volts to represent the digit 8 and, over time, lost 6% of its voltage, the value is now 37.5 volts. Not a huge drop, but what if +35 volts is used to represent the digit 7? Is the 37.5 a high 35 or a low 40? See the problem? 4. Alternately, by using a binary system, there are only two options: Full on and full off. So, now our +45 voltage device could lose up to 50% of its voltage level before a problem of interpretation arises. B. Binary storage devices 1. Now that weve seen why using a binary system is a good idea for building computers, lets take a quick look at how the whole on-or-off thing is implemented. 2. Any hardware device used in a binary computer must meet the following criteria: a. The device has two stable energy states (1 and 0). b. The two states are separated by an energy barrier so that a 0 doesnt accidentally become a 1 and vice-versa. c. The state the device is in (i.e., storing a 1 or a 0) can be determined without destroying the stored value. d. The state of the device can be switched from 1 to 0, or vice versa, by applying a sufficient amount of energy. 3. Originally, memory of a computer was implemented using magnetic cores. a. That is, small iron oxide-coated doughnuts that could be magnetized. b. Each doughnut had a wire running through the center of it. c. The direction of the magnetic field of the core determined whether the binary value was 1 or 0. 4. But, using a lot of magnetic cores can cause a computer to get real big real fast. Even if you could put 500 cores/in2 (which was the norm back in the 1960s), to have 1 gigabyte (that is, 1 billion bytes or 8 billion bits) of memory, youd need a memory chip more than 30 stories tall! 5. These days, memory is built using transistors. a. Transistors are constructed from materials called semiconductors like silicon. b. These transistors act like light switches (theyre either on or off), but with no mechanical or moving parts. c. And, up to 1 billion transistors can fit into a space only 1 cm2. Thats less than half an inch!

III.

Boolean Logic and Gates A. To get started, lets review some of the information from Gaddis Chapter 4 that is relevant here. B. If you recall, we discussed the AND, OR, and NOT operators. C. These three operators are the operators found in one branch of mathematics called Boolean Logic. 1. Boolean logic deals with the rules for working with the logical values of true and false. 2. This is easily translated, in computer-speak, to 1 (for true) and 0 (for false). 3. Traditional math uses operators like + and to build arithmetic expressions. 4. Boolean logic uses the operators of AND (sometimes written as ), OR (sometimes written as +), and NOT (also written as a line over the expression being negated, e.g., a ) to build Boolean expressions that will evaluate to either true or false. 5. The AND and OR operators are binary operators while the NOT operator is an unary operator. 6. A structure known as a truth table is used to show how each operator can be used, all possible combinations of true and false for the operands, and the logical value for each expression. 7. If you recall, the truth table for each operator is as follows: AND Logical Operator a true false true false b true true false false OR Logical Operator a true false true false b true true false false NOT Logical Operator a true false NOT a (a ) true true a OR b (a + b) true true true false a AND b (a b) true false false false

D. Gates 1. A gate is essentially an on/off electronic device. It uses a collection of binary (1 and 0) inputs to produce a binary output (1 or 0). That is, it essentially transforms a collection of binary inputs into a single binary output. 2. Gates can be used to set up a wide range of transformation rules. But here, were only going to work with the AND, OR, and NOT gates. 3. These gates and their corresponding inputs and output can be represented visually like this: AND Gate OR Gate

a 0 0 1 1

b 0 1 0 1

ab 0 0 0 1 NOT Gate

a 0 0 1 1

b 0 1 0 1

a+b 0 1 1 1

a 0 1

1 0

4. So, how are these gates built? One or more transistors are used. Depending on how theyre set up, its easy to create a variety of simple gates. 5. Lets look at the simplest gate a NOT gate. a. A NOT gate can be constructed from a single transistor. A visualization can be seen on the next page.

Construction of a NOT gate

b. The power supply (logical-1) is connected to the collector while the emitter is connected to ground (logical-0). c. If the input is set to 1, the transistor is on. Any current coming from the power supply goes on through the complete circuit and out to ground. When this happens, the output voltage of the gate (through the line marked Output) is 0. That is, a 1 goes in and a 0 comes out. d. If the input is set to 0, the transistor is off. Any current coming from the power supply is blocked (cant go to ground). When this happens, the current is forced to Output and the output voltage of the gate is 1. That is, a 0 goes in and a 1 comes out. 6. Now lets see how an AND gate is constructed. a. Since on the truth table for AND there are two inputs, well need two transistors connected in series to handle the two inputs. A visualization of this gate can be seen on the next page.

Construction of a NAND gate b. But, this doesnt quite give us the results we want. In this case, if both transistors are in the on state (that is, Input-1 and Input-2 are both set to 1), the current passes through both transistors and out to ground. That means the voltage to Output is 0. c. If only 1 of the transistors is on, then the current cannot pass to ground and the voltage to Output is 1. The same is true if both transistors are off the voltage to Output is 1. d. This is the exact opposite of what we want! In fact, this is called a NAND gate which stands for NOT AND. 7. So, how do we fix the problem? a. We know that the NOT gate will negate the value of a single input, right? What if we added a NOT gate to the output line of the NAND gate? The picture on the next page shows the result.

Construction of a AND gate b. So, now if the input of both transistors is 1, the output voltage is still 0. But since the NOT gate is there, the output is changed to 1. c. Conversely, if either or both inputs are 0, the output voltage is 1, but is changed to 0 by the NOT gate. 8. What about an OR gate? a. In this situation, we still use 2 transistors. The difference is theyll be connected in parallel rather than in series. This can be seen in the picture on the next page.

Construction of a NOR gate

9.

b. Now, since each transistor is connected to ground independent of the other, if either transistors input is 1 (that is, the transistor is ON), the voltage can still go to ground. The output voltage is 0. c. If both transistors are off, nothing makes it to ground and the output voltage is 1. d. Again, this is the exact opposite of the results we want. This is called a NOR gate (NOT OR). How do we fix this problem? Another NOT gate maybe? a. If we add a NOT gate to the output, as seen in the picture on the next page, if either (or both) transistors are on, the voltage goes to ground and the output voltage is 0. But, with the NOT gate, its changed to 1.

Construction of an OR gate b. Conversely, if both transistors are off, no voltage goes to ground and the output voltage is 1. But, with the NOT gate, its changed to 0. Building Computer Circuits 1. We can use a collection of logic gates to build a circuit. The resulting circuit will transform a set of binary inputs into a set of binary outputs. The output values will depend on the current values of the inputs. 2. Heres one example of an circuit that uses 1 AND gate, 1 OR gate, and 2 NOT gates:

IV.

3. Since theres a direct relationship between Boolean expressions and circuit diagrams like this, we can represent Boolean expressions visually as a circuit diagram and each output in the diagram as a Boolean expression.

a. For example, we can see that output c is a result of an OR operation on a and b (its perfectly legal to split inputs up and send them into several gates). b. On the diagram, we can tell that one of the inputs for the OR gate is a and the other is b. c. We could also represent this as a Boolean expression: c = (a OR b) Note: This is NOT an assignment statement in a program! This says that the value of c will be a result of the OR operation done on the inputs of a and b. d. Writing the Boolean expression to represent the output of d is a little more involved. e. The final output is negated by the last NOT gate, so we could start by saying d = NOT (something will go in here). f. The last gate immediately before the NOT is an AND gate. It has two inputs one from a NOT b and the other from the OR gate. Since both the NOT and the OR must take place before the AND gate, we can write the expression like this: d = NOT( (a OR b) AND (NOT b) ) g. Lets plug in some values for the inputs and see what the results are. Suppose the input for a is 1 and the input for b is 0. Heres what the results would be:

4. There are a variety of circuit construction algorithms. Were going to take a

quick look at the sum-of-products algorithm. a. Step 1 is to construct a truth table. The number of rows in the truth table will depend on the number of inputs. If there are n inputs, there will be 2n rows in the truth table to show all the possible combinations of 1s and 0s. So, if we have 3 inputs, wed have a table with 8 rows. For every row in the table, the desired output(s) for each combination of inputs are listed. Heres a table that has 3 inputs and 2 desired outputs (the outputs in this table are completely arbitrary and for demonstration purposes only).

a 0 0 0 0 1 1 1 1

Inputs b 0 0 1 1 0 0 1 1

c 0 1 0 1 0 1 0 1

Outputs Output-1 Output-2 0 1 0 0 1 1 0 1 0 0 0 0 1 1 0 0

b. In step 2, once we have the truth table written out, we pick any output column and scan it for a value of 1. For every value of 1 thats found, a Boolean sub-expression is built. i. Lets use the Output-1 column for this example. There are two places where we see a value of 1. ii. In the first case (row 3), both a and c have values of 0 and b has a value of 1. Any time an input has a value of 0, we apply the NOT operator in the Boolean expression. So, the Boolean expression for the first case would be ( a b c ) iii. In the second case (row 7), a and b have a value of 1 while c has a value of 0. In this case, the Boolean expression for this would be

(a b c)

iv. Once we have the sub-expressions built, we can combine them, two at

a time, using OR gates: ( a b c ) + ( a b c ) c. Now that we have a Boolean expression that produces the desired result, we can use AND, OR, and NOT gates to implement the AND, OR, and NOT operators seen in the Boolean expression.

5. Note that this circuit is not the optimal circuit. Since a essentially negates itself in the two expressions, we can leave it out and simplify the circuit like this:

You might also like