Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates
Objectives In this chapter, you will learn about The binary numbering system Boolean logic and gates Building computer circuits Control circuits
Introduction Chapter 4 focuses on hardware design (also called logic design) How to represent and store information inside a computer How to use the principles of symbolic logic to design gates How to use gates to construct circuits that perform operations such as adding and comparing numbers, and fetching instructions
The Binary Numbering System A computer s internal storage techniques are different from the way people represent information in daily lives Information inside a digital computer is stored as a collection of binary data Two types of information representation External representation Internal representation
Figure 4.1 Distinction Between External and Internal Representation of Information
Binary Representation of Numeric and Textual Information Binary numbering system Base-2 positional numbering system Built from ones and zeros Each position is a power of 2 1101 = 1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 20 Decimal numbering system Base-10 Each position is a power of 10 3052 = 3 x 10 3 + 0 x 10 2 + 5 x 10 1 + 2 x 10 0
Binary Representation of Numeric and Textual Information. Binary-to-decimal algorithm Whenever there is a 1 in a column, add the positional value of that column to a running sum Whenever there is a 0 in a column, add nothing The final sum is the decimal value of this binary number Example 10011 = 1 2 4 +0+0+1 2 1 +1 20 = 16+0+0+2+1=19
. Figure 4.2 Binary-to-Decimal Conversion Table Invitation to Computer Science, 5th Edition 8
Binary Representation of Numeric and Textual Information. Decimal-to-binary algorithm Convert the value 19 to binary 19 2 quotient = 9 remainder = 1 9 2 quotient = 4 remainder = 1 4 2 quotient = 2 remainder = 0 2 2 quotient = 1 remainder = 0 1 2 quotient = 0 remainder = 1 The result is 10011 Order for reading the remainder digits Invitation to Computer Science, 5th Edition 9
Binary Representation of Numeric and Textual Information (continued) Representing integers Decimal integers are converted to binary integers Maximum number of binary digits that can be used to store an integer: 16, 32, or 64 bits Given k bits, the largest unsigned integer is 2 k - 1 Given 16 bits, the largest is 2 16-1 = 65535 Arithmetic overflow
Binary Representation of Numeric and Textual Information Representing signed integers Sign/magnitude notation One of a number of different techniques for representing positive and negative whole numbers Not used often in real computer systems Two s complement representation Total number of values that can be represented with n bits is 2 n
Binary Representation of Numeric and Textual Information (continued) Representing real numbers Real numbers can be put into binary scientific notation: a x 2 b Example: 101.11 x 2 0 Number then normalized so that first significant digit is immediately to the right of the binary point Example:.10111 x 2 3 Mantissa and exponent then stored
Binary Representation of Numeric and Textual Information (continued) Characters are mapped onto binary numbers ASCII code set 8 bits per character; 256 character codes UNICODE code set 16 bits per character; 65,536 character codes Text strings are sequences of characters in some encoding
Figure 4.3 ASCII Conversion Table
Binary Representation of Sound and Images Multimedia data is sampled to store a digital form with or without detectable differences Representing sound data Sound data must be digitized for storage in a computer Digitizing means periodic sampling of amplitude values
Figure 4.5 Digitization of an Analog Signal (a) Sampling the Original Signal (b) Recreating the Signal from the Sampled Values
Binary Representation of Sound and Images (continued) From samples, original sound can be approximated To improve the approximation Sample more frequently (sampling rate) Use more bits for each sample value (bit depth)
Binary Representation of Sound and Images (continued) Representing image data Images are sampled by measuring the intensity values of distinct points located at regular intervals across the image s surface (scanning) Each sampled point is a pixel Image quality depends on number of bits at each pixel
Binary Representation of Sound and Images (continued) Image encoding schemes RGB encoding scheme Most common format for storing color images True Color 24-bit color-encoding scheme
Binary Representation of Sound and Images (continued) Data compression Data compression algorithms Attempt to represent information in ways that preserve accuracy while using significantly less space Run-length encoding Replaces a sequence of identical values v1, v2,..., vn by a pair of values (v, n) Compression ratio Measures how much compression schemes reduce storage requirements of data Variable length code sets Often used to compress text Can also be used with other forms of data
Figure 4.8 Using Variable Length Code Sets (a) Fixed Length (b) Variable Length
Binary Representation of Sound and Images (continued) Lossless compression schemes No information is lost in the compression It is possible to exactly reproduce the original data Lossy compression schemes Do not guarantee that all of the information in the original data can be fully and completely recreated
The Reliability of Binary Representation Electronic devices are most reliable in a bistable environment Bistable environment Distinguishing only two electronic states Current flowing or not Direction of flow Computers are bistable: binary representations
Binary Storage Devices Magnetic core Historic device for computer memory Tiny magnetized rings; flow of current sets the direction of magnetic field Binary values 0 and 1 are represented using the direction of the magnetic field
Binary Storage Devices (continued) Transistors Solid-state switches; either permit or block current flow A control input causes state change Constructed from semiconductors Can be printed photographically on a wafer of silicon to produce a device known as an integrated circuit
Figure 4.11 Simplified Model of a Transistor
Binary Storage Devices (continued) Circuit board Interconnects all the different chips needed to run a computer system
Figure 4.10 Relationships Among Transistors, Chips, and Circuit Boards
Boolean Logic and Gates: Boolean Logic Boolean logic describes operations on true/false values True/false maps easily onto bistable environment Boolean logic operations on electronic signals can be built out of transistors and other electronic devices
Boolean Logic (continued) Boolean operations a AND b True only when a is true and b is true a OR b True when a is true, b is true, or both are true NOT a True when a is false and vice versa
Boolean Logic (continued) Boolean expressions Constructed by combining together Boolean operations Example: (a AND b) OR ((NOT b) AND (NOT a)) Truth tables capture the output/value of a Boolean expression A column for each input plus the output A row for each combination of input values
(a) (c) (a) Figure 4.12 Truth Table for the AND Operation (b) Figure 4.13 Truth Table for the OR Operation (c) Figure 4.14 Truth Table for the NOT Operation (b )
Boolean Logic (continued) Example: (a AND b) OR ((NOT b) and (NOT a)) a b Value 0 0 1 0 1 0 1 0 0 1 1 1
Gates Gates Hardware devices built from transistors to mimic Boolean logic Transforms a set of (0,1) input values into a single (0,1) output value AND gate Two input lines, one output line Outputs a 1 when both inputs are 1
Gates (continued) OR gate Two input lines, one output line Outputs a 1 when either input is 1 NOT gate One input line, one output line Outputs a 1 when input is 0 and vice versa
Figure 4.16 Construction of a NOT Gate
Figure 4.17 Construction of NAND and AND Gates (a) A Two-transistor NAND Gate (b) A Three-transistor AND Gate
Figure 4.18 Construction of NOR and OR Gates (a) A Two-transistor NOR Gate (b) A Three-transistor OR Gate
Figure 4.15 The Three Basic Gates and Their Symbols
Gates (continued) Abstraction in hardware design Map hardware devices to Boolean logic Design more complex devices in terms of logic, not electronics Conversion from logic to hardware design can be automated
Building Computer Circuits: Introduction A circuit is a collection of logic gates Transforms a set of binary inputs into a set of binary outputs Values of the outputs depend only on the current values of the inputs Combinational circuits have no cycles in them (no outputs feed back into their own inputs)
Figure 4.19 Diagram of a Typical Computer Circuit
A Circuit Construction Algorithm Sum-of-products algorithm is one way to design circuits Truth table to Boolean expression to gate layout
A Circuit Construction Algorithm (continued) Step 1: Truth Table Construction Determine how the circuit should behave under all possible circumstances If a circuit has N input lines and if each input line can be either a 0 or a 1, then: There are 2N combinations of input values, and the truth table has 2N rows
A Truth Table for a Circuit with 8 Input Combinations
A Circuit Construction Algorithm (continued) Step 2: Subexpression Construction Using AND and NOT Gates Choose any one output column of the truth table built in step 1, and scan down that column Every place that you find a 1 in that output column, you build a Boolean subexpression that produces the value 1 for exactly that combination of input values and no other
Output Column Labeled Output-1 from the Previous Truth Table
A Circuit Construction Algorithm (continued) Step 3: Subexpression Combination Using OR Gates Take each of the subexpressions produced in step 2 and combine them, two at a time, using OR gates Step 4: Circuit Diagram Production Construct the final circuit diagram
Figure 4.20 Circuit Diagram for the Output Labeled Output-1
A Circuit Construction Algorithm (continued) Algorithms for circuit optimization Reduce the number of gates needed to implement a circuit
Figure 4.21 The Sum-of-Products Circuit Construction Algorithm
A Circuit Construction Algorithm (continued) Sum-of-products algorithm Truth table captures every input/output possible for circuit Repeat process for each output line Build a Boolean expression using AND and NOT for each 1 of the output line Combine together all the expressions with ORs Build circuit from whole Boolean expression
Examples of Circuit Design and Construction Compare-for-equality circuit Addition circuit Both circuits can be built using the sum-ofproducts algorithm
A Compare-for-Equality Circuit Compare-for-equality circuit CE compares two unsigned binary integers for equality Built by combining together 1-bit comparison circuits (1-CE) Integers are equal if corresponding bits are equal (AND together 1-CD circuits for each pair of bits)
A Compare-for-Equality Circuit (continued) 1-CE circuit truth table a b Output 0 0 1 0 1 0 1 0 0 1 1 1
Figure 4.22 One-Bit Compare-for-Equality Circuit
A Compare-for-Equality Circuit (continued) 1-CE Boolean expression First case: (NOT a) AND (NOT b) Second case: a AND b Combined: ((NOT a) AND (NOT b)) OR (a AND b)
Figure 4.23 N-Bit Compare for Equality Circuit
An Addition Circuit Addition circuit Performs addition on two unsigned binary integers Built from 1-bit adders (1-ADD) Starting with rightmost bits, each pair produces A value for that order A carry bit for next place to the left
An Addition Circuit (continued) 1-ADD truth table Input One bit from each input integer One carry bit (always zero for rightmost bit) Output One bit for output place value One carry bit
Figure 4.24 The 1-ADD Circuit and Truth Table
Figure 4.25 Sum Output for the 1-ADD Circuit
Figure 4.26 Complete 1-ADD Circuit for 1-Bit Binary Addition
Figure 4.27 The Complete Full Adder ADD Circuit
Control Circuits Do not perform computations Choose order of operations or select among data values Major types of controls circuits Multiplexors Select one of inputs to send to output Decoders Sends a 1 on one output line based on what input line indicates
Control Circuits (continued) Multiplexor form 2N regular input lines N selector input lines 1 output line Multiplexor purpose Given a code number for some input, selects that input to pass along to its output Used to choose the right input value to send to a computational circuit
Figure 4.28 A Two-Input Multiplexor Circuit Invitation to Computer Science, 5th Edition 67
Control Circuits (continued) Decoder Form N input lines 2N output lines N input lines indicate a binary number, which is used to select one of the output lines Selected output sends a 1, all others send 0
Control Circuits (continued) Decoder purpose Given a number code for some operation, trigger just that operation to take place Numbers might be codes for arithmetic (add, subtract, and so on) Decoder signals which operation takes place next
Figure 4.29 A 2-to-4 Decoder Circuit
Figure 4.30 Example of the Use of a Decoder Circuit
Figure 4.31 Example of the Use of a Multiplexor Circuit 72
Summary Digital computers use binary representations of data: numbers, text, multimedia Binary values create a bistable environment, making computers reliable Boolean logic maps easily onto electronic hardware Circuits are constructed using Boolean expressions as an abstraction Computational and control circuits can be built from Boolean gates