Schneider - Ch04 - Inv To CS 8e
Schneider - Ch04 - Inv To CS 8e
Schneider - Ch04 - Inv To CS 8e
The Building
Blocks: Binary
Numbers,
Boolean Logic,
and Gates
Learning Objectives (1 of 2)
• Translate between base-ten and base-two numbers,
and represent negative numbers using both sign-
magnitude and two’s complement representations
• Explain how fractional numbers, characters, sounds,
and images are represented inside the computer
• Build truth tables for Boolean expressions and
determine when they are true or false
• Describe the relationship between Boolean logic and
electronic gates
Learning Objectives (2 of 2)
• Construct circuits using the sum-of-products circuit
design algorithm, and analyze simple circuits to
determine their truth tables
• Explain how large, complex circuits, like 32-bit adder
or compare-for-equality circuits, are constructed from
simpler, 1-bit components
• Describe the purpose and workings of multiplexer and
decoder control circuits
Introduction
• This chapter introduces the fundamental building
blocks of all computer systems
– Binary representation
– Boolean logic
– Gates
– Circuits
• This chapter examines what the computing agent
looks like and how it is able to execute instructions
and produce results
The Binary Numbering System (1 of 21)
• How can an electronic (or magnetic) machine
represent information?
• Key requirements: clear, unambiguous, and reliable
• External representation is human-oriented
– Base-10 numbers
– Keyboard characters
• Internal representation is computer-oriented
– Base-2 numbers
– Base-2 codes for characters
The Binary Numbering System (2 of 21)
• Binary is the simple idea of On/Off, Yes/No,
True/False, and Positive/Negative.
• Binary is important to computing systems because of
it’s stability and reliability.
– Even when an electrical system degrades, there is still
a clear “On/Off.”
• All data stored inside a computer is stored in binary
(also called machine language) and interpreted to
display on the screen in human language.
The Binary Numbering System (3 of 21)
The Binary Numbering System (4 of 21)
• The binary numbering system is a base-2
positional numbering system
• Base ten:
– Uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9
– Each place corresponds to a power of 10
– 1,943 = (1 × 103) + (9 × 102) + (4 × 101) + (3 × 100)
• Base two:
– Uses 2 digits: 0 and 1
– Each place corresponds to a power of 2
– 1101 = (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20) = 13
The Binary Numbering System (5 of 21)
FIGURE 4.2 Binary-to-decimal conversion table
Binary Decimal Binary Decimal
0 0 10000 16
1 1 10001 17
10 2 10010 18
11 3 10011 19
100 4 10100 20
101 5 10101 21
110 6 10110 22
111 7 10111 23
1000 8 11000 24
1001 9 11001 25
1010 10 11010 26
1011 11 11011 27
1100 12 11100 28
1101 13 11101 29
1110 14 11110 30
1111 15 11111 31
The Binary Numbering System (6 of 21)
• Converting from binary to decimal
– Add up powers of two where a 1 appears in the
binary number
• Converting from decimal to binary
– Repeatedly divide by two and record the remainder
– Example, convert 11:
▪ 11 ÷ 2 = 5, remainder = 1, binary number = 1
▪ 5 ÷ 2 = 2, remainder = 1, binary number = 11
▪ 2 ÷ 2 = 1, remainder = 0, binary number = 011
▪ 1 ÷ 2 = 0, remainder = 1, binary number = 1011
The Binary Numbering System (7 of 21)
• Computers use fixed-length binary numbers for
integers, e.g., 4 bits could represent 0 to 15
• Arithmetic overflow: when the computer tries to
make a number that is too large, e.g., 14 + 2 with 4
bits
• Binary addition: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1,
1 + 1 = 10 (that is, 0 with a carry of 1)
• Example: 0101 + 0011 = 1000
The Binary Numbering System (8 of 21)
• Signed integers include negative numbers
• Sign/magnitude notation uses 1 bit for the sign
and the rest for the value
+5 = 0101, -5 = 1101
0 = 0000 and 1000!
• Two’s complement representation: to make the
negative of a number, flip every bit and add one
+5 = 0101, -5 = 1010 + 1 = 1011
0 = 0000, -0 = 1111 + 1 = 0000
The Binary Numbering System (9 of 21)
• Floating point numbers use binary scientific
notation
– Scientific notation, base 10: 1.35 × 10-5
– Base 2: 3.2510 = 11.012 = 1.101 × 21
• Characters and text: map characters onto binary
numbers in a standard way
– ASCII (8-bit numbers for each character)
– Unicode (Minimum of 16-bit numbers for each
character)
The Binary Numbering System (10 of 21)
• Sounds and images require converting naturally
analog representations to digital
representations
• Sound waves characterized by:
– Amplitude: height of the wave at a moment in time
– Period: length of time until wave pattern repeats
– Frequency: number of cycles per unit time
The Binary Numbering System (11 of 21)
The Binary Numbering System (12 of 21)
• Digitize: to convert to a digital form
• Sampling: record sound wave values at fixed,
discrete intervals
• To reproduce sound, approximate using samples
• Quality is determined by
– Sampling rate: number of samples per second
▪ More samples ► more accurate waveform
– Bit depth: number of bits per sample
▪ More bits ► more accurate amplitude
The Binary Numbering System (13 of 21)
The Binary Numbering System (14 of 21)
• Image sampling: record color or intensity at fixed,
discrete intervals in two dimensions
• Pixels: individual recorded samples
• RGB encoding scheme:
– Colors are combinations of red, green, and blue
– One byte each for red, green, and blue
• Raster graphics store picture as two dimensional
grid of pixel values
The Binary Numbering System (15 of 21)
The Binary Numbering System (16 of 21)
The Binary Numbering System (17 of 21)
• What is the space necessary to store the following
data?
– 1000 integer values
– 10-page text paper
– 60-second sound file
– 480 by 640 image
• Data compression: storing data in a reduced-size
form to save space/time
– Lossless: data can be perfectly restored
– Lossy: data cannot be perfectly restored
The Binary Numbering System (18 of 21)
Letter 4-bit Encoding Variable Length Encoding
A 0000 00
I 0001 10
H 0010 010
W 0011 110
E 0100 0110
O 0101 0111
M 0110 11100
K 0111 11101
U 1000 11110
N 1001 111110
P 1010 1111110
L 1011 1111111
(a) (b)
FIGURE 4.14
Output a AND b
Inputs: Inputs:
(also written a .
a b
b)
False False False
False True False
True False False
True True True
FIGURE 4.15
Output a OR b
Inputs: Inputs:
(also written a +
a b
b)
False False False
False True True
True False True
True True True
FIGURE 4.16
1
0 0 1 0 1
+ 0 1 0 0 1
0 1 1 1 0