next up previous
Next: About this document Up: My Home Page

Let's Get Digital!

The principles of logic are clearly essential in computer software, as we must verify that conditional statements correctly implement our desired objectives.

More surprisingly, the logic of tex2html_wrap_inline305 , tex2html_wrap_inline307 , and tex2html_wrap_inline309 forms the foundations of how computer hardware is designed and built.

The reason is that it is straightforward to build digital circuits which implement these logical functions.

Observe that the logical conditions tex2html_wrap_inline311 , tex2html_wrap_inline313 , and tex2html_wrap_inline315 can be built out of physical switches.

The earliest computers used electronic relays and then vacuum tubes to construct these switches, which are now made out of transistors.

The black boxes which implement tex2html_wrap_inline317 , tex2html_wrap_inline319 , and tex2html_wrap_inline321 are called logic gates.

Determining the Output Table of a Circuit

The behavior of any circuit which does not include feedback (the output of a gate fed back in as an input to that same gate) can be represented by a truth table or logical formula.

We can build a truth table by observing what happens to the output for each possible input to the circuit.

tabular190

Note that this circuit computes the exclusive or, tex2html_wrap_inline329 .

Determining the Output Function of a Circuit

We can also reconstruct the output function of a circuit symbolically, by tracing from the input signals and appropriately enclosing within parentheses.

The resulting formula tex2html_wrap_inline331 can easily be seen to be tex2html_wrap_inline333 .

A rule that can be used to construct the output function is to to start at the output gate G and

  1. Report the output function of the gate leading into the first input to G (within parentheses, and assuming G is not a tex2html_wrap_inline341 gate)
  2. Report the type of gate G ( tex2html_wrap_inline345 or tex2html_wrap_inline347 or tex2html_wrap_inline349 )
  3. Report the output function of the gate leading into the second input to G (within parentheses)

We stop this reporting process when the inputs are simple signals, instead of gates.

This is an example of a recursive algorithm, because it solves the problem in terms of solutions to smaller versions of the problem.

We will see many more examples of recursive algorithms later in the semester.

Notice that this procedure works correctly because there are no feedback connections. Otherwise we would get into an infinite loop if the circuit had a cycle!

Synthesizing Logical Statements

Given a logical function realized by the rightmost column of an arbitrary truth table, does there always exist a logical statement having this as its truth table?

If so, it means that we can make any circuit we want out of the basic logic gates.

tabular202

A set of operations is universal if it can represent any possible truth table.

Can you give an example of a truth table which cannot be represented by just tex2html_wrap_inline359 and tex2html_wrap_inline361 ?

Building Statements from Truth Tables

In fact, tex2html_wrap_inline363 , tex2html_wrap_inline365 , and tex2html_wrap_inline367 are universal.

Why? Each row of a truth table corresponds to a condition under which the formula is true.

tabular210

This is true if tex2html_wrap_inline375 is true, or if tex2html_wrap_inline377 is true, or if tex2html_wrap_inline379 is true. Thus,

displaymath299

Equivalently, it is false if tex2html_wrap_inline381 , so

displaymath300

tabular215

In fact, it is possible to construct any possible circuit from just one type of gate - either NAND (not and) or NOR (not or) gates suffice.

tabular222

How can we show that NOR and NAND are universal?

How we can build tex2html_wrap_inline399 , tex2html_wrap_inline401 , and tex2html_wrap_inline403 out of NAND or NOR gates?

Binary Numbers

Internally, computers work with binary (or base-2) numbers.

This is convenient because logical false (or off) can represent the 0 digit while logical true (or on) can represent the 1 digit.

Any number can be represented as a binary number in exactly the same way that any number can be represented as a decimal (base-10) number.

The key is that the value of a symbol depends upon its position. The ith digit from the right in a base b number is multiplied by tex2html_wrap_inline409 .

Thus the base-10 number 11101 means

eqnarray231

Thus the base-2 number 11101 means

displaymath301

We can convert any base-10 number into a binary number by repeatedly subtracting off the largest possible powers of 2.

To convert decimal 29 to binary, observe there are no 32's or higher powers of two. After subtracting off one 16, we have 13. After subtracting off one 8, we have 5. After subtracting off one 4, we have no 2's and one 1. This gives the binary number 11101.

It is important that you be able to easily convert between binary and decimal numbers!

Anybody celebrating their 16th or 32nd birthday is flipping their bits! Why?

I can count to 1023 on my fingers. Can you?

Binary Addition

Adding numbers in binary is analogous to adding them in decimal. Start at the right, add the last two digits, and move as the carry the part which is too big to fit in one digit.

Adding two 1's leaves a number too big to represent as one binary digit (or bit), so we write 0 as the sum and carry a 1 to represent the value 2.

tabular236

In general, for each step of the process, we have to add three bits together; one from each number and the carry.

tabular241

Using our logic design techniques, we can build a logical formula corresponding to this truth table, and then build a circuit which implements it.

The half-adder takes two bits and added them to get sum and carry bits.

The full-adder combines two half-adders to add two bits and a carry.

By cascading together a collection of half and full-adders, we can built a circuit to add up arbitrarily long integers.




next up previous
Next: About this document Up: My Home Page

Steve Skiena
Tue Aug 24 17:31:13 EDT 1999