Download Presentation

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates

768 Views

Download Presentation
## Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Chapter 4: The Building Blocks: Binary Numbers, Boolean**Logic, and Gates Invitation to Computer Science, Java Version, Second Edition**Objectives**In this chapter, you will learn about: • The binary numbering system • Boolean logic and gates • Building computer circuits • Control circuits Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Numeric and Textual Information**• Binary numbering system • Base-2 • Built from ones and zeros • Each position is a power of 2 1101 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 • Decimal numbering system • Base-10 • Each position is a power of 10 3052 = 3 x 103 + 0 x 102 + 5 x 101 + 2 x 100 Invitation to Computer Science, Java Version, Second Edition**Figure 4.2**Binary-to-Decimal Conversion Table Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Numeric and Textual Information**(continued) • Representing integers • Decimal integers are converted to binary integers • Given k bits, the largest unsigned integer is 2k - 1 • Given 4 bits, the largest is 24-1 = 15 • Signed integers must also represent the sign (positive or negative) Invitation to Computer Science, Java Version, Second Edition**10 347**• 34 7 • 3 4 • 0 3 Converting from base 10 to base 2 • Note that the individual digits of an integer can be obtained by repeatedly dividing it by 10 and recording the successive remainders, for example: • Given a positive base 10 integer, converting to base 2 can be done by repeatedly dividing the integer by 2 and recording the successive remainders, which will be 0 or 1. The sequence written in the reverse order of how they were generated is the base 2 representation of the integer. Invitation to Computer Science, Java Version, Second Edition**Converting from base 10 to base 2**• For example, suppose we wish to convert 343 to base 2. • The repeated division and remainders can be displayed in a table with the rightmost column listing the remainders. • Thus, 34310 = 1010101112. Invitation to Computer Science, Java Version, Second Edition**Converting from base 2 to base 10**• Given a positive base 2 integer, converting to base 10 can be done by multiplying each of the bits by 2 to the power corresponding to the position of the bit in the number. The sum of these products is the base 10 representation of the number. The computation starts with the least significant bit, i.e. bit position 0. Thus we process the bits in this order: 101010111 Invitation to Computer Science, Java Version, Second Edition**Converting from base 2 to base 10**• For example, suppose we wish to convert 101010111 to base 10. The computation can be displayed as in the table. • Thus, 1010101112 = 34310. Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Numeric and Textual Information**(continued) • Representing real numbers • Real numbers may be put into binary scientific notation: a x 2b • Example: 101.11 x 20 • Number then normalized so that first significant digit is immediately to the right of the binary point • Example: .10111 x 23 • Mantissa and exponent then stored Invitation to Computer Science, Java Version, Second Edition**Memory Size Shorthand**8 bits = 1 byte 210 = 1K (= 1,024) 1KB = 1 kilobyte 220 = 1M (= 1,048,576) 1MB = 1 megabyte 230 = 1G (= 1,073,741,824) 1GB = 1 gigabyte 240 = 1T (= 1,099,511,627,776) 1TB = 1 terabyte Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Numeric and Textual Information**(continued) • Characters are mapped onto binary numbers • ASCII code set • 8 bits (1 byte) per character; 256 character codes • UNICODE code set • 16 bits (2 bytes) per character; 65,536 character codes • Text strings are sequences of characters in some encoding • A standard double spaced printed page is roughly 25 lines with 80 characters per line. • 25 × 80 = 2000 2k characters • 1 page 2k ASCII characters 1k UNICODE characters Invitation to Computer Science, Java Version, Second Edition**ASCII Code Chart**• Visit www.LookupTables.com to see UNICODE chart Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Sound and Images (continued)**• From samples, original sound may be approximated • To improve the approximation: • Sample more frequently • Use more bits for each sample value Invitation to Computer Science, Java Version, Second Edition**Figure 4.5**Digitization of an Analog Signal (a) Sampling the Original Signal (b) Recreating the Signal from the Sampled Values Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Sound and Images (continued)**• Representing image data • Images are sampled by reading color and intensity values at even intervals across the image • Each sampled point is a pixel • Image quality depends on number of bits at each pixel Invitation to Computer Science, Java Version, Second Edition**Binary Representation of Sound and Images (continued)**Invitation to Computer Science, Java Version, Second Edition**Representing Colors using RGB method**Invitation to Computer Science, Java Version, Second Edition**RGB 24-bit Color Representation**• Each color has 3 components Red-Green-Blue • Each component has value from 0 to 255 • It requires 8 bits to represent each component • It requires 24 bits to represent a color • 24 bits can be grouped as 6 groups of 4 bits • Each 4 bit group represents a hexadecimal digit • Colors can be written as a 6 digit hex number Invitation to Computer Science, Java Version, Second Edition**RGB 24-bit Color Representation**• Example: Red Green Blue Decimal 102 255 153 Binary 01100110 11111111 10011001 24 bit 011001101111111110011001 hexadecimal 6 6 F F 9 9 Invitation to Computer Science, Java Version, Second Edition**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: hence binary representations Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**Figure 4.9**Using Magnetic Cores to Represent Binary Values Invitation to Computer Science, Java Version, Second Edition**Magnetic Core**If a current equal to half the magnetizing current is passed along X3 and another half current is passed along Y3, then only the red core at the intersection will receive the full magnetic field. The red core will be magnetized but all the other cores will be unaffected. Invitation to Computer Science, Java Version, Second Edition**1955 Popular Mechanics Article**Invitation to Computer Science, Java Version, Second Edition**Binary Storage Devices (continued)**• Transistors • Solid-state switches: either permits or blocks current flow • A control input causes state change • Constructed from semiconductors Invitation to Computer Science, Java Version, Second Edition**Figure 4.11**Simplified Model of a Transistor Invitation to Computer Science, Java Version, Second Edition**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 may be built out of transistors and other electronic devices Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Boolean operations • a AND b • True only when a is true and b is true • a OR b • True when either a is true or b is true, or both are true • NOT a • True when a is false, and vice versa Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Boolean expressions • Constructed by combining together Boolean operations • Example: (a AND b) OR ((NOT b) AND (NOT a)) • When not using parentheses, a defined precedence determines the order of evaluation • For Boolean operators, the order is NOT highest AND OR ,, < , >, , lowest Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Precedence Examples: NOT b AND NOT a same as (NOT b) AND (NOT a) a OR b AND c same as a OR (b AND c) NOT a OR b same as (NOT a) OR b a OR NOT b AND c same as a OR ((NOT b) AND c) Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Precedence Examples • Given x = 3, y = 7, determine the value of the following • (x = 3) AND NOT (y = x) • NOT (y 3) AND (x = 3) • NOT (y > x) OR (x > 0) • NOT ((y > x) OR (x > 0)) • (y > x) AND NOT (y > 10) OR (x > 0) • (y > x) AND NOT ((y > 10) OR (x > 0)) • (y < x) OR NOT (y > 10) AND (x > 0) • (y < x) AND (x > 0) OR NOT (y > 10) Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**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 • Example: (a AND b) OR ((NOT b) AND (NOT a)) Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Example in more detail: • First list the possible values for each variable • Order of computing the truth table values (a AND b) OR ((NOT b) AND (NOT a)) 0000 0110 1001 1111 Order Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Example in more detail: • First list the possible values for each variable • Then compute the column, in order, for each subexpression • Order of computing the truth table values (a AND b) OR ((NOT b) AND (NOT a)) 0001010 0010110 1001001 1110101 Order 1 2 3 Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Example in more detail: • First list the possible values for each variable • Then compute the column, in order, for each subexpression • Order of computing the truth table values (a AND b) OR ((NOT b) AND (NOT a)) 00010110 00101010 10010001 11101001 Order 1 2 4 3 Invitation to Computer Science, Java Version, Second Edition**Boolean Logic (continued)**• Example in more detail: • First list the possible values for each variable • Then compute the column, in order, for each subexpression • Order of computing the truth table values (a AND b) OR ((NOT b) AND (NOT a)) 000110110 001001010 100010001 111101001 Order 1 5 2 4 3 Invitation to Computer Science, Java Version, Second Edition**Gates**• Gates • Hardware devices built from transistors to mimic Boolean logic • AND gate • Two input lines, one output line • Outputs a 1 when both inputs are 1 Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**Figure 4.15**The Three Basic Gates and Their Symbols Invitation to Computer Science, Java Version, Second Edition**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 may be automated Invitation to Computer Science, Java Version, Second Edition**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) Invitation to Computer Science, Java Version, Second Edition**Figure 4.19**Diagram of a Typical Computer Circuit Invitation to Computer Science, Java Version, Second Edition**A Circuit Construction Algorithm**• Sum-of-products algorithm is one way to design circuits: • Truth table to Boolean expression to gate layout Invitation to Computer Science, Java Version, Second Edition**Figure 4.21**The Sum-of-Products Circuit Construction Algorithm Invitation to Computer Science, Java Version, Second Edition**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 Invitation to Computer Science, Java Version, Second Edition**Example Of Circuit Design 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) Invitation to Computer Science, Java Version, Second Edition