Logical Operators

Author(s): Vince Lee
Publication: ZX-Appeal
Pub Details: ZX-Appeal Summer 88
Date: Summer 1988
Pages: 13-14

A Course In Digital Electronics

If you’ve never experimented with digital electronics but you’ve programmed in BASIC with such statements as,

10  IF A AND B = 3 THEN GOTO 50
20 IF C OR D = 7 THEN PRINT E

chances are you already know more about digital electronics than you suspect.

Unlike amplifiers, digital electronics is made up of logic switches called gates. They are concidered as either on or off, true or false, high or low. In the early days a person would build them out of relays but now they are available in integrated circuit form. There are two main families that are widely used, the 7400 series TTL and the 4000 series CMOS.

There are eight basic gate building blocks. A two input AND gate will produce a high output if both input A and input B is high. A two input OR gate will produce a high output if either input A or input B is high. An EXCLUSIVE OR gate will produce a high output if input A is different than input B. An INVERTER produces the opposite output condition from its input. Combining these gates with another INVERTER will produce four more new gates with the opposite conditions, the NAND gate, the NOR gate, the EXCLUSIVE NOR gate and the non-inverting BUFFER. When different gates are combined they can be made to perform elaborate tasks.

In 1847 George Boole developed a system called Boolean algebra. It showed how a logical condition could be translated into an equation. We can synthesize a logic circuit with ZX operators and have the computer perform all the calculations. This list which contain all the different input conditions is called the Truth Table. It allows us to analize the circuit without actually having to build it.

Example 1 shows the solution to the “Goat-Wolf-Corn” problem. A farmer empoys a hired hand that is not too bright. The hired hand is to keep the farmer’s goat out of the corn barn while the door is open. There is also danger of a wolf that lurks nearby who will eat the goat. It is assumed that the situation is safe if the goat and the wolf are not visible and that the wolf does not eat corn. The farmer builds a circuit that contains three switches. All the hired hand need to do is to throw the switches when the situation occurs, door open, goat in sight, wolf in sight. The digital circuit will sound the alarm if a dangerous condition occurs which will alert the farmer. Does the circuit work? Try it and see.

The “Truth Table program” will calculate all the conditions for a logic circuit. It asks for the number of inputs and the equation. There are some examples available that may help you see how the program works. However there are two limitations. The program is limited to a maximum of six inputs numbered A to F although it can easily be modified to handle more. The other is that Boolean algebra will only work with combination logic, not with sequential logic. Sequential logic covers the area of flip flops, counters, shift registers etc. which relys on the previous conditions. It would require a much more sophisticated program and that may come in some future time.

If you’re interested in learning more about digital electronics there are some very good books on the market. The favorites have always been the “TTL Cookbook” or the “Cmos Cookbook” by Don Lancaster. Other good ones include “Cmos/TTL, A User’s Guide with Projects” by Joseph J. Carr. And the example for the “Goat-Wolf-Corn” problem is from “Digital Computer Circuits & Concepts” by Bill Deem, Kenneth Muchow and Anthony Zeppa.

EIGHT BASIC GATES

Eight basic gates: AND, NAND, OR, NOR gate symbols with TTL/CMOS numbers, ZX expressions and truth tables
Eight basic gates: AND, NAND, OR, NOR gate symbols with TTL/CMOS numbers, ZX expressions and truth tables
Exclusive OR, Exclusive NOR, Buffer and Inverter gates; Examples 1-4 logic circuits with their ZX expressions
Exclusive OR, Exclusive NOR, Buffer and Inverter gates; Examples 1-4 logic circuits with their ZX expressions
   1 REM      THE TRUTH TABLE
BY V. LEE
THIS PROGRAM WILL PRODUCE A
TRUTH TABLE FROM A GIVEN BOOLEAN
EXPRESSION WRITTEN WITH COMPUTER
OPERATORS.

WHEN THE PROGRAM STOPS, ENTER

Z TO COPY
C TO CONTINUE
5 GOTO 100
10 LET A=Y
15 RETURN
20 LET B=Y
25 RETURN
30 LET C=Y
35 RETURN
40 LET D=Y
45 RETURN
50 LET E=Y
55 RETURN
60 LET F=Y
65 RETURN
100 LET L$="F E D C B A "
110 LET U$="[20 graphic characters]"
120 LET S$=" "
130 PRINT AT 4,7;"THE TRUTH TABLE";AT 11,2;"ENTER THE NUMBER OF INPUTS";AT 13,11;"(MAX. 6)"
140 INPUT I
150 IF I>6 THEN GOTO 140
160 PRINT AT 11,1;"ENTER THE BOOLEAN EXPRESSION";AT 13,11;" "
170 INPUT E$
200 CLS
210 PRINT E$;AT 4,0;L$(19-3*I TO );" Q";AT 5,0;U$( TO (I+1)*3)
220 FOR X=0 TO 2**I-1
230 LET N=X
240 FOR L=1 TO I
250 LET Y=(N-2*INT (N/2))
260 LET N=INT (N/2)
270 LET S$((I+1-L)*3-2)=STR$ Y
280 GOSUB L*10
290 NEXT L
300 LET S$((I+1)*3)=STR$ VAL E$
310 PRINT S$
320 NEXT X
330 STOP
340 GOTO 120
Lines 100-110 as printed, with the graphic string U$
Lines 100-110 as printed, with the graphic string U$

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.