980 likes | 1.04k Vues
Invitation to Computer Science 6th Edition. Chapter 4 The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Introduction. Chapter 4 focuses on hardware design (also called logic design) How to represent and store information inside a computer-- The binary numbering system
E N D
Invitation to Computer Science 6th Edition Chapter 4 The Building Blocks: Binary Numbers, Boolean Logic, and Gates
Introduction • Chapter 4 focuses on hardware design (also called logic design) • How to represent and store information inside a computer--The binary numbering system • How to use the principles of symbolic logic to design gates--Boolean logic and gates • How to use gates to construct circuits that perform operations such as adding and comparing numbers, and fetching instructions--Building computer circuits • Control circuits Invitation to Computer Science, 6th Edition
Introduction • Computing agent • Abstract concept representing any object capable of understanding and executing our instructions • Fundamental building blocks of all computer systems • Binary representation • Boolean logic • Gates • Circuits Invitation to Computer Science, 6th Edition 3
The Binary Numbering System • Binary representation of numeric and textual information • Two types of information representation • External representation • Internal representation • Binary is a base-2 positional numbering system Invitation to Computer Science, 6th Edition 4
Figure 4.1 Distinction Between External Memory and Internal Representation of Information Invitation to Computer Science, 6th Edition
Binary Representation of Numeric and Textual Information Invitation to Computer Science, 6th Edition
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 Invitation to Computer Science, 6th Edition
Figure 4.2 Binary-to-Decimal Conversion Table Invitation to Computer Science, 6th Edition
Binary Representation of Numeric and Textual Information (continued) • To convert a decimal value into its binary equivalent • Use the decimal-to-binary algorithm • 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 2k-1 • Given 16 bits the largest is 216-1=65535 • Arithmetic overflow • Operation that produces an unsigned value greater than 65,535 Invitation to Computer Science, 6th Edition
Binary Representation of Numeric and Textual Information (continued) Invitation to Computer Science, 6th Edition
Binary Representation of Numeric and Textual Information (continued) How to express signed integer? Sign/Magnitude notation (old computer) Two's complement notation (current computer) Invitation to Computer Science, 6th Edition
Sign/Magnitude notation 1(sign bit) 110001 (total: 7 bits, computer A) When it is a signed value, it is -49 When it is a unsigned value, it is 113 1(sign bit) 0110001 (total: 8 bits, computer B) When it is a signed value, it is -49 When it is a unsigned value, it is 177 You must tell the computer if it is signed or unsigned integer. The number of bit depends on computer (8bit, 16bit, 32bit, 64bit) Invitation to Computer Science, 6th Edition
Two's complement notation Why we have this solution? Because of two zeros problem in Sign/Magnitude notation : 10000, 00000 if (a = b) do operation 1 else do operation 2 Invitation to Computer Science, 6th Edition
Two's complement notation If A > 0 then do nothing else get complement value of each bit a <- a+1 Eg: -3 (3bit): 3 -> 011 -> 100 -> 101 -3 (4bit): 3 -> 0011 -> 1100 -> 1101 The number of bit depends on computer (8bit, 16bit, 32bit, 64bit) Easier method: Get complement value of each bit until first 1 Eg: -3 (3bit): 3-> 011 -> 101 -3 (4bit) : 3 -> 0011 -> 1101 No substraction in two’s complement notation. Convert to complement value. Eg 5 – 3 = 5 + (-3) Invitation to Computer Science, 6th Edition
Two's complement notation Bit pattern Decimal Value 001 +1 010 +2 011 +3 100 -4 101 -3 110 -2 111 -1 Invitation to Computer Science, 6th Edition
Compare value range Suppose we have k bit. Sign/Magnitude notation: -(2k-1 – 1) to (2k-1 – 1) Eg 3bit: -3 ~ +3 Two's complement notation: -(2k-1) to (2k-1 – 1) Eg 3bit: -4 ~ +3 Why different? Because Sign/Magnitude notation has two zeros while two’s complement notation has only one zero. Though two’s complement notation is difficult to human, it much clearer to computer. Invitation to Computer Science, 6th Edition
Binary <-> Decimal (Fractional number) Binary -> Decimal 0.1101 = 1*2-1 + 1*2-2 + 0*2-3 + 1*2-4 = 0.5 + 0.25 + 0 + 0.0625 = 0.8125 Decimal -> Binary 0.8125 0.8125 * 2 = 1.625 ------ Get 1 0.625 * 2 = 1.25 ------ Get 1 0.25 * 2 = 0.5 ------ Get 0 0.5 * 2 = 1 ------ Get 1 Final: 0.1101 (Attention: compare to integer conversion)
Fractional Numbers • Fractional numbers (12.34 and –0.001275) • Can be represented in binary by using signed-integer techniques • Scientific notation • ±M x B±E • M is the mantissa, B is the exponent base (usually 2), and E is the exponent • Normalize the number • First significant digit is immediately to the right of the binary point Invitation to Computer Science, 6th Edition
Representing real numbers Real numbers should 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 Binary Representation of Numeric and Textual Information (continued) Invitation to Computer Science, 6th Edition
Normalization Example Binary Normalization 5.75 = 101.11 = 0.10111 * 23 Mantissa and exponent then stored ±M * B ±E 00010111000011 (8 bits for mantissa, 6 bits for exponent) 5.75 = 101.11 = 0.010111 * 24 = 1.0111 * 22 0.010111 * 24 and 1.0111 * 22 are not normalized number
Textual Information • Code mapping • Assigning each printable letter or symbol in our alphabet a unique number • ASCII • International standard for representing textual information in the majority of computers • Uses 8 bits to represent each character • UNICODE • Uses a 16-bit representation for characters rather than the 8-bit format of ASCII Invitation to Computer Science, 6th Edition
Figure 4.3 ASCII Conversion Table Invitation to Computer Science, 6th Edition
Binary Representation of Sound and Images • Digitalrepresentation • Values for a given object are drawn from a finite set • Analogrepresentation • Objects can take on any value • Figure 4.4 • Amplitude of the wave: measure of its loudness • Period of the wave (T): time it takes for the wave to make one complete cycle (pitch—highness or lowness) • Frequency f: total number of cycles per unit time (cycles/seconds or hertz) Invitation to Computer Science, 6th Edition
Figure 4.4 Example of Sound Represented as a Waveform Invitation to Computer Science, 6th Edition
Binary Representation of Sound and Images (continued) • Digitizing means periodic sampling of amplitude values • Sampling rate • Measures how many times per second we sample the amplitude of the sound wave • Bit depth • Number of bits used to encode each sample • MP3 • Most popular and widely used digital audio format Invitation to Computer Science, 6th Edition
Figure 4.5 Digitization of an Analog Signal (a) Sampling the Original Signal (b) Re-creating the Signal from the Sampled Values Invitation to Computer Science, 6th Edition
Binary Representation of Sound and Images (continued) From samples, original sound can be approximated To improve the approximation Sample more frequently Use more bits for each sample value Invitation to Computer Science, 6th Edition
Representing image data Images are sampled by reading color and intensity values Each sampled point is a pixel Image quality depends on number of bits at each pixel 0.05~0.1mm Scanning Measuring the intensity values of distinct points located at regular intervals across the image’s surface Binary Representation of Sound and Images (continued) Invitation to Computer Science, 6th Edition
Binary Representation of Sound and Images (continued) Invitation to Computer Science, 6th Edition
Data Compression Why we need data compression? Because the original data need too much space. Eg. 3,000,000 pixels/photograph * 24 bits/pixel = 72million bits. Data compression algorithms Attempt to represent information in ways that preserve accuracy while using significantly less space Invitation to Computer Science, 6th Edition
Data Compression Lossless compressionschemes No information is lost in the compression It is possible to exactly reproduce the original data Lossy compressionschemes Do not guarantee that all of the information in the original data can be fully and completely recreated Compression ratio Measures how much compression schemes reduce storage requirements of data Compression rate = size of the uncompressed data / size of the compressed data Invitation to Computer Science, 6th Edition
Binary Representation of Sound and Images (continued) • Run-length encoding • Replaces a sequence of identical values v1, v2, . . ., vnby a pair of values (v, n) • for image compression • Eg. (255 255 255), (255, 0, 0), (255, 255, 255), (255, 0, 0), (255, 255, 255) → (255, 4), (0, 2), (255, 4), (0, 2), (255, 3) • Variable length code sets • Often used to compress text • Can also be used with other forms of data Invitation to Computer Science, 6th Edition
Data Compression Simple compression method - “variable length code sets” - for text compress Letter 4 bit encoding Variable length encoding A 0000 00 I 0001 10 H 0010 010 W 0100 110 H A W A I I → 0010, 0000, 0100, 0000, 0001, 0001 → 001, 00, 110, 00, 10, 10 Invitation to Computer Science, 6th Edition
Figure 4.8 Using Variable Length Code Sets (a) Fixed Length (b) Variable Length Invitation to Computer Science, 6th Edition
The Reliability of Binary Representation • Computers use binary representation for reasons of reliability • Building a base-10 “decimal computer” • Requires finding a device with 10 distinct and stable energy states that can be used to represent the 10 unique digits (0, 1, . . . , 9) of the decimal system • Bistable environment • Only two (rather than 10) stable states separated by a huge energy barrier Invitation to Computer Science, 6th Edition
Binary Storage Devices • Magnetic core • Historic device for computer memory • Tiny magnetized rings; flow of current sets the direction of magnetic field direction of magnetic field • Binary values 0 and 1are represented using the direction of the magnetic field Invitation to Computer Science, 6th Edition
Figure 4.9 Using Magnetic Cores to Represent Binary Values Invitation to Computer Science, 6th Edition
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 to produce a device known as an integrated circuit • Circuit board • Interconnects all the different chips needed to run a computer system Invitation to Computer Science, 6th Edition
Figure 4.10 Relationships Among Transistors, Chips, and Circuit Boards Invitation to Computer Science, 6th Edition
Binary Storage Devices (continued) • Figure 4.11 • Control (base): used to open or close the switch inside the transistor • ON state: current coming from the In line (Collector) can flow directly to the Out line (Emitter), and the associated voltage can be detected by a measuring device Invitation to Computer Science, 6th Edition
Figure 4.11 Simplified Model of a Transistor Invitation to Computer Science, 6th Edition
Boolean Logic • Boolean logic • Construction of computer circuits is based on this • Boolean expression • Any expression that evaluates to either true or false • Constructed by combining together Boolean operations • Example: (a AND b) OR ((NOT b) AND (NOT a)) • Truth table • A column for each input plus the output • A row for each combination of input values Invitation to Computer Science, 6th Edition
Figure 4.12 Truth Table for the AND Operation Truth Table: Can express the idea that the AND operation produces the value true if and only if both of its components are true Invitation to Computer Science, 6th Edition
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 Invitation to Computer Science, 6th Edition
Boolean Logic (continued) • Boolean operations • AND, OR, NOT • Binary operators • Require two operands • Unary operator • Requires only one operand • NOT operation • Reverses, or complements, the value of a Boolean expression Invitation to Computer Science, 6th Edition