Chapter 1
Digital Design and Computer Architecture, 2nd Edition
David Money Harris and Sarah L. Harris
Chapter 1 <1>
Chapter 1 :: Topics
• Background
• The Game Plan
• The Art of Managing Complexity
• The Digital Abstraction
• Number Systems
• Logic Gates
• Logic Levels
• CMOS Transistors
• Power Consumption
Chapter 1 <2>
Number Systems
• Decimal numbers
1000's column
10's column
1's column
100's column
Positional Numeral Systems:
https://en.wikipedia.org/wiki/Positional_notation
537410 =
• Binary numbers
8's column
2's column
1's column
4's column
11012 =
Chapter 1 <3>
Number Systems
• Decimal numbers
1000's column
10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones
• Binary numbers
8's column
2's column
1's column
4's column
11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310
one one no one
eight four two one
Chapter 1 <4>
Powers of Two
• 20 = • 28 =
• 21 = • 29 =
• 22 = • 210 =
• 23 = • 211 =
• 24 = • 212 =
• 25 = • 213 =
• 26 = • 214 =
• 27 = • 215 =
Chapter 1 <5>
Powers of Two: Base of a Position
• 20 = 1 • 28 = 256
• 21 = 2 • 29 = 512
• 22 = 4 • 210 = 1024, ~= 1000, 1K
• 23 = 8 • 211 = 2048, 2K
• 24 = 16 • 212 = 4096, 4K
• 25 = 32 • 213 = 8192, 8K
• 26 = 64 • 214 = 16384, 16K
• 27 = 128 • 215 = 32768, 32K
• Handy to memorize up to 29
Chapter 1 <6>
Number Conversion
• Decimal to binary conversion:
– Convert 100112 to decimal
• Decimal to binary conversion:
– Convert 4710 to binary
Chapter 1 <7>
Number Conversion
• Decimal to binary conversion:
– Convert 100112 to decimal
– 16×1 + 8×0 + 4×0 + 2×1 + 1×1 = 1910
• Decimal to binary conversion:
– Convert 4710 to binary
– Find the combination of base numbers (1, 2, 4, 8, 16, 32,
…) and line them up according to the position
– 32×1 + 16×0 + 8×1 + 4×1 + 2×1 + 1×1 = 1011112
Chapter 1 <8>
Binary Values and Range
• N-digit decimal number
– How many values?
– Range?
– Example: 3-digit decimal number:
• N-bit binary number
– How many values?
– Range:
– Example: 3-digit binary number:
Chapter 1 <9>
Binary Values and Range
• N-digit decimal number
– How many values? 10N
– Range? [0, 10N - 1]
– Example: 3-digit decimal number:
• 103 = 1000 possible values
• Range: [0, 999]
• N-bit binary number
– How many values? 2N
– Range: [0, 2N - 1]
– Example: 3-digit binary number:
• 23 = 8 possible values
• Range: [0, 7] = [0002 to 1112]
Chapter 1 <10>
Hexadecimal Numbers
• Base 16
• Shorthand for binary
Chapter 1 <11>
Hexadecimal Numbers
Hex Digit Decimal Equivalent Binary Equivalent
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15
Chapter 1 <12>
Hexadecimal Numbers
Hex Digit Decimal Equivalent Binary Equivalent
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111 1-digit HEX number ==
8 8 1000
4-digit binary number
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
Chapter 1 <13>
Hexadecimal to Binary Conversion
• Hexadecimal to binary conversion:
– Convert 4AF16 (also written 0x4AF) to binary
• Hexadecimal to decimal conversion:
– Convert 0x4AF to decimal
Chapter 1 <14>
Hexadecimal to Binary Conversion
• Hexadecimal to binary conversion:
– Convert 4AF16 (also written 0x4AF) to binary
– 0100 1010 11112 1-digit HEX number ==
4-digit binary number
• Hexadecimal to decimal conversion:
– Convert 4AF16 to decimal
– 162×4 + 161×10 + 160×15 = 119910
Chapter 1 <15>
Bits, Bytes, Nibbles…
• Bits 10010110
most least
significant significant
bit bit
byte
• Bytes & Nibbles
10010110
nibble
• Bytes CEBF9AD7
most least
significant significant
byte byte
Chapter 1 <16>
Large Powers of Two
• 210 = 1 kilo ≈ 1000 (1024)
• 220 = 1 mega ≈ 1 million (1,048,576)
• 230 = 1 giga ≈ 1 billion (1,073,741,824)
Chapter 1 <17>
Estimating Powers of Two
• What is the value of 224?
• How many values can a 32-bit variable
represent?
Chapter 1 <18>
Estimating Powers of Two
• What is the value of 224?
24 × 220 ≈ 16 million
• How many values can a 32-bit variable
represent?
22 × 230 ≈ 4 billion
Chapter 1 <19>
Addition
• Decimal
3734
+ 5168
• Binary
1011
+ 0011
Chapter 1 <20>
Addition
• Decimal 11 carries
3734
+ 5168
8902
• Binary 11 carries
1011
+ 0011
1110
Chapter 1 <21>
Binary Addition Examples
• Add the following
4-bit binary
1001
+ 0101
numbers
• Add the following 1011
4-bit binary + 0110
numbers
Chapter 1 <22>
Binary Addition Examples
• Add the following 1
4-bit binary 1001
numbers
+ 0101
1110
111
• Add the following 1011
4-bit binary + 0110
numbers 10001
Overflow!
Chapter 1 <23>
Overflow
• Digital systems operate on a fixed number of
bits
• Overflow: when result is too big to fit in the
available number of bits
• See previous example of 11 + 6
Chapter 1 <24>
To be continued …
• The rest of the slides are for your reference
only. We will cover signed, unsigned
numbers, 2’s complement in Chapter 2.4.
Chapter 1 <25>
Signed Binary Numbers
• Sign/Magnitude Numbers
• Two’s Complement Numbers
Chapter 1 <26>
Sign/Magnitude Numbers
• 1 sign bit, N-1 magnitude bits
• Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0 A : {a N -1 , a N -2 ,! a2 , a1 , a0 }
– Negative number: sign bit = 1 n -2
A = ( -1)
a n -1 i
åa 2
i =0
i
• Example, 4-bit sign/mag representations of ± 6:
+6 =
-6=
• Range of an N-bit sign/magnitude number:
Chapter 1 <27>
Sign/Magnitude Numbers
• 1 sign bit, N-1 magnitude bits
• Sign bit is the most significant (left-most) bit
– Positive number: sign bit = 0 A : {a N -1 , a N -2 ,! a2 , a1 , a0 }
– Negative number: sign bit = 1 n -2
A = ( -1)
a n -1 i
åa 2
i =0
i
• Example, 4-bit sign/mag representations of ± 6:
+6 = 0110
- 6 = 1110
• Range of an N-bit sign/magnitude number:
[-(2N-1-1), 2N-1-1]
Chapter 1 <28>
Sign/Magnitude Numbers
• Problems:
– Addition doesn’t work, for example -6 + 6:
1110
+ 0110
10100 (wrong!)
– Two representations of 0 (± 0):
1000
0000
Chapter 1 <29>
Two’s Complement Numbers
• Don’t have same problems as sign/magnitude
numbers:
– Addition works
– Single representation for 0
Chapter 1 <30>
Two’s Complement Numbers
• Msb has value of -2N-1
n -2
A = an -1 ( -2 n -1
) + åa 2 i
i
i =0
• Most positive 4-bit number:
• Most negative 4-bit number:
• The most significant bit still indicates the sign
(1 = negative, 0 = positive)
• Range of an N-bit two’s comp number:
Chapter 1 <31>
Two’s Complement Numbers
• Msb has value of -2N-1
n -2
A = an -1 ( -2 n -1
) + åa 2 i
i
i =0
• Most positive 4-bit number: 0111
• Most negative 4-bit number: 1000
• The most significant bit still indicates the sign
(1 = negative, 0 = positive)
• Range of an N-bit two’s comp number:
[-(2N-1), 2N-1-1]
Chapter 1 <32>
“Taking the Two’s Complement”
• Flip the sign of a two’s complement number
• Method:
1. Invert the bits
2. Add 1
• Example: Flip the sign of 310 = 00112
Chapter 1 <33>
“Taking the Two’s Complement”
• Flip the sign of a two’s complement number
• Method:
1. Invert the bits
2. Add 1
• Example: Flip the sign of 310 = 00112
1. 1100
2. + 1
1101 = -310
Chapter 1 <34>
Two’s Complement Examples
• Take the two’s complement of 610 = 01102
• What is the decimal value of 10012?
Chapter 1 <35>
Two’s Complement Examples
• Take the two’s complement of 610 = 01102
1. 1001
2. + 1
10102 = -610
• What is the decimal value of the two’s
complement number 10012?
1. 0110
2. + 1
01112 = 710, so 10012 = -710
Chapter 1 <36>
Two’s Complement Addition
• Add 6 + (-6) using two’s complement
numbers
0110
+ 1010
• Add -2 + 3 using two’s complement numbers
1110
+ 0011
Chapter 1 <37>
Two’s Complement Addition
• Add 6 + (-6) using two’s complement
numbers 111
0110
+ 1010
10000
• Add -2 + 3 using two’s complement numbers
111
1110
+ 0011
10001
Chapter 1 <38>
Increasing Bit Width
• Extend number from N to M bits (M > N) :
– Sign-extension
– Zero-extension
Copyright © 2012 Elsevier
Chapter 1 <39>
Sign-Extension
• Sign bit copied to msb’s
• Number value is same
• Example 1:
– 4-bit representation of 3 = 0011
– 8-bit sign-extended value: 00000011
• Example 2:
– 4-bit representation of -5 = 1011
– 8-bit sign-extended value: 11111011
Chapter 1 <40>
Zero-Extension
• Zeros copied to msb’s
• Value changes for negative numbers
• Example 1:
– 4-bit value = 00112 = 310
– 8-bit zero-extended value: 00000011 = 310
• Example 2:
– 4-bit value = 1011 = -510
– 8-bit zero-extended value: 00001011 = 1110
Chapter 1 <41>
Number System Comparison
Number System Range
Unsigned [0, 2N-1]
Sign/Magnitude [-(2N-1-1), 2N-1-1]
Two’s Complement [-2N-1, 2N-1-1]
For example, 4-bit representation:
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Unsigned 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two's Complement
0000
1111 1110 1101 1100 1011 1010 1001
1000
0001 0010 0011 0100 0101 0110 0111 Sign/Magnitude
Chapter 1 <42>