CS 226: Digital Logic Design: Lecture 2: Binary Numbers
CS 226: Digital Logic Design: Lecture 2: Binary Numbers
Ashutosh Trivedi
0 1 I S
1
0 1
0
S0
Binary Arithmetic
Ashutosh Trivedi – 2 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
– How do we construct numbers greater than 9?
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
– How do we construct numbers greater than 9?
– Use 0 and give convenient names to 10 (ten), 100 (hundred), 1000
(thousand), etc. and count with them. (examples).
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
– How do we construct numbers greater than 9?
– Use 0 and give convenient names to 10 (ten), 100 (hundred), 1000
(thousand), etc. and count with them. (examples).
– Convenient representation?
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
– How do we construct numbers greater than 9?
– Use 0 and give convenient names to 10 (ten), 100 (hundred), 1000
(thousand), etc. and count with them. (examples).
– Convenient representation?
– Place-value system
The number 270 from a 9th century inscription in Gwalior, India [source]
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Recap: Decimal Numbers
– digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.
– How do we construct numbers greater than 9?
– Use 0 and give convenient names to 10 (ten), 100 (hundred), 1000
(thousand), etc. and count with them. (examples).
– Convenient representation?
– Place-value system
The number 270 from a 9th century inscription in Gwalior, India [source]
– Examples: 270, and 7392, and 7392.56.
Ashutosh Trivedi – 3 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Place-Value System
1 1
7392.56 = 7 ∗ 1000 + 3 ∗ 100 + 9 ∗ 10 + 2 ∗ 1 + 5 ∗ +6∗
10 100
= 7 ∗ 103 + 3 ∗ 102 + 9 ∗ 101 + 2 ∗ 100 + 5 ∗ 10−1 + 6 ∗ 10−2 .
Discussion:
– Is there something special about having 10 digits?
– Can we define arbitrary large numbers using fewer or more digits?
– Examples:
1. binary-digits = {0, 1}
2. octal-digits = {0, 1, 2, 3, 4, 5, 6, 7}
3. hexadecimal-digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
4. Sexagesimal-digits 1
Babylonian clay tablet YBC 7289 with annotations. The diagonal displays an approximation
of the square root of 2 in four sexagesimal figures, 1 24 51 10, which is good to about six
decimal digits. [source]
Ashutosh Trivedi – 5 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Base-r Systems
Let the digits of a base-r system be B = {0, 1, 2, . . . , r − 1}.
A base-r number
(an an−1 · · · a0 .a−1 a−2 · · · a−m )r
where ai ∈ B is equal to decimal number:
Ashutosh Trivedi – 6 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Base-r Systems
Let the digits of a base-r system be B = {0, 1, 2, . . . , r − 1}.
A base-r number
(an an−1 · · · a0 .a−1 a−2 · · · a−m )r
where ai ∈ B is equal to decimal number:
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
= ((5 ∗ 2) + 1)
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
= ((5 ∗ 2) + 1)
= (((2 ∗ 2 + 1) ∗ 2) + 1)
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
= ((5 ∗ 2) + 1)
= (((2 ∗ 2 + 1) ∗ 2) + 1)
= ((((1 ∗ 2) ∗ 2 + 1) ∗ 2) + 1)
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
= ((5 ∗ 2) + 1)
= (((2 ∗ 2 + 1) ∗ 2) + 1)
= ((((1 ∗ 2) ∗ 2 + 1) ∗ 2) + 1)
= (((((0 ∗ 2 + 1) ∗ 2) ∗ 2 + 1) ∗ 2) + 1)
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
11 = (10 + 1)
= ((5 ∗ 2) + 1)
= (((2 ∗ 2 + 1) ∗ 2) + 1)
= ((((1 ∗ 2) ∗ 2 + 1) ∗ 2) + 1)
= (((((0 ∗ 2 + 1) ∗ 2) ∗ 2 + 1) ∗ 2) + 1)
= 1 ∗ 23 + 1 ∗ 21 + 1
= (1011)2 .
Ashutosh Trivedi – 7 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
1
0.6875 = (1 + 0.375)
2
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
1
0.6875 = (1 + 0.375)
2
1 1
= (1 + (0 + 0.75))
2 2
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
1
0.6875 = (1 + 0.375)
2
1 1
= (1 + (0 + 0.75))
2 2
= ···
1 1 1 1
= (1 + (0 + (1 + (1 + 0))))
2 2 2 2
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
1
0.6875 = (1 + 0.375)
2
1 1
= (1 + (0 + 0.75))
2 2
= ···
1 1 1 1
= (1 + (0 + (1 + (1 + 0))))
2 2 2 2
= (0.1011)2 .
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
How to do the converse?
Examples:
– What is 0.6875 in binary?
1
0.6875 = (1 + 0.375)
2
1 1
= (1 + (0 + 0.75))
2 2
= ···
1 1 1 1
= (1 + (0 + (1 + (1 + 0))))
2 2 2 2
= (0.1011)2 .
Ashutosh Trivedi – 8 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Octal and Hexadecimal Numbers
Decimal Binary Octal Hexadecimal
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A = 10
11 1011 13 B = 11
12 1100 14 C = 12
13 1101 15 D = 13
14 1110 16 E = 14
15 1111 17 F = 15
Binary Arithmetic
Ashutosh Trivedi – 10 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Let’s generalize Decimal Arithmetic
– Addition
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
Ashutosh Trivedi – 11 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Let’s generalize Decimal Arithmetic
– Addition
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Subtraction
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
Ashutosh Trivedi – 11 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Let’s generalize Decimal Arithmetic
– Addition
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Subtraction
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Multiplication
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
Ashutosh Trivedi – 11 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers
Let’s generalize Decimal Arithmetic
– Addition
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Subtraction
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Multiplication
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
– Division
– What do you need to remember?
– What is the algorithm?
– How to extend that in Binary?
Ashutosh Trivedi – 11 of 11
Ashutosh Trivedi Lecture 2: Binary Numbers