You are on page 1of 53

Digital Logic & Design

Lecture 02
Number Systems and Codes

• Decimal Number System


• Caveman Number System
• Binary Number System
• Hexadecimal Number System
• Octal Number System

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal Number System

• Ten unique numbers 0,1,2,3,4,5,6,7,8,9


• Combination of digits
• Positional Number System

• 275 = 2 x 102 + 7 x 101 + 5 x 100


– Base or Radix 10
– Weight 1, 10, 100, 1000 ….

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Representing Fractions

• Fractions can be represented in decimal number


system in a manner

= 3 x 102 + 8 x 101 + 2 x 100 + 9 x 10-1


+ 1 x 10-2
= 300 + 80 + 2 + 0.9 + 0.01
= 382.91

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Caveman Number System

• ∑, ∆, >, Ω and ↑
• Base – 5 Number System

• ∆Ω↑∑ = 220

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Caveman Number System
Decimal Number Caveman Number Decimal Number Caveman Number

0 ∑ 10 >∑
1 ∆ 11 >∆
2 > 12 >>
3 Ω 13 >Ω
4 ↑ 14 >↑
5 ∆∑ 15 Ω∑
6 ∆∆ 16 Ω∆
7 ∆> 17 Ω>
8 ∆Ω 18 ΩΩ
9 ∆↑ 19 Ω↑

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Caveman Number System

• Mr. Caveman is using a base 5 number system. Thus


the number ∆Ω↑∑ in decimal is
= ∆ x 53 + Ω x 52 + ↑ x 51 + ∑ x 50
= ∆ x 125 + Ω x 25 + ↑ x 5 + ∑ x 1
= (1) x 125 + (3) x 25 + (4) x 5 + (0) x 1
= 125 + 75 + 20 + 0 = 220

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Binary Number System

• Two unique numbers 0 and 1


• Base – 2
• A binary digit is a bit
• Combination of bits to represent larger values

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Binary Number System

Decimal Number Binary Number Decimal Number Binary Number

0 0 10 1010
1 1 11 1011
2 10 12 1100
3 11 13 1101
4 100 14 1110
5 101 15 1111
6 110 16 10000
7 111 17 10001
8 1000 18 10010
9 1001 19 10011

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Combination of Binary Bits

• Combination of Bits
• 100112 = 1910
= (1 x 24) + (0 x 23) + (0 x 22) + (1 x 21)
+ (1 x 20)
= (1 x 16) + (0 x 8) + (0 x 4) + (1 x 2)
+ (1 x 1)
= 16 + 0 + 0 + 2 + 1
= 19

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Fractions in Binary

• Fractions in Binary
• 1011.1012 = 11.625
= (1 x 23) + (0 x 22) + (1 x 21) + (1 x 20)
+ (1 x 2-1) + (0 x 2-2) + (1 x 2-3)
= (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1)
+ (1 x 1/2) + (0 x 1/4) + (1 x 1/8)
= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125
= 11.625
• Floating Point Notations

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal-Binary Conversion

• Binary to Decimal Conversion


– Sum-of-Weights
– Adding weights of non-zero terms
• Decimal to Binary Conversion
– Sum-of-Weights (in reverse)
– Repeated Division by 2

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal to binary conversion using
Sum of weight
Number Weight Result after subtraction Binary

392 256 392-256=136 1


136 128 136-128=8 1
8 54 0
8 32 0
8 16 0
8 8 8-8=0 1
0 4 0
0 2 0
0 1 0

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal-Binary Conversion

• Binary to Decimal Conversion


– Sum-of-Weights
– Adding weights of non-zero terms
100112
(1 24 )  (0  23 )  (0  22 )  (1 21 )
 (1 2 ) 0

Terms 16,0,0.2 and 1


19
Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal-Binary Conversion

• Binary to Decimal Conversion


– Sum-of-Weights
– Adding weights of non-zero terms

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal-Binary Conversion

• Binary to Decimal Conversion


– Sum-of-Weights
– Adding weights of non-zero terms

100112  16  2  1  19
1011.1012  8  2  1  1
2 8
 11  5
8
 11.625
Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Binary to Decimal Conversion

• Sum-of-Weights
– Expression base number & weights
– Sum terms
– Paper and pencil method
• Sum of non-zero terms
– Mental Arithmetic, quick method
– Sum of weights of non-zero terms
Binary to Decimal Conversion

Sum-of-Weights
100112 =( ? ) 10
•(1 x 24) + (0 x 23) + (0 x 22) + (1 x 21)
+ (1 x 20)
•(1 x 16) + (0 x 8) + (0 x 4) + (1 x 2)
+ (1 x 1)
•Terms 16, 0, 0, 2 and 1
•16+2+1
•19
Binary to Decimal Conversion

• Add weights of non-zero terms


• Weights increase/decrease by power of 2

• 100112 = 16 + 2 + 1 = 19

• 1011.1012 = 8 + 2 + 1 + 1/2 + 1/8


= 11 + 5/8
= 11.625
Decimal to Binary Conversion

• Sum-of-Weights method used in reverse


– Highest binary weight less than the decimal
number
– Subsequent smaller weights that add up to
decimal number
• Repeated division by 2
– Paper and pencil method
– Number repeatedly divided by 2
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136
128
64
32
16
8
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8
64
32
16
8
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8 1 b7
8 64
32
16
8
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8 1 b7
8 64 0 b6
32
16
8
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8 1 b7
8 64 0 b6
8 32 0 b5
8 16 0 b4
8 8 8-8 =0
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8 1 b7
8 64 0 b6
8 32 0 b5
8 16 0 b4
8 8 8-8 =0 1 b3
4
2
1
Decimal to Binary Conversion
Sum-of-Weights
number Weight Result after subtraction Binary Bit
392 256 392-256 = 136 1 b8
136 128 136-128 = 8 1 b7
8 64 0 b6
8 32 0 b5
8 16 0 b4
8 8 8-8 =0 1 b3
0 4 0 b2
0 2 0 b1
0 1 0 b0
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
24 12 0 (b4)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
24 12 0 (b4)
12 6 0 (b5)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
24 12 0 (b4)
12 6 0 (b5)
6 3 0 (b6)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
24 12 0 (b4)
12 6 0 (b5)
6 3 0 (b6)
3 1 1 (b7)
Decimal to Binary Conversion
Repeated division by 2
number Quotient after division Remainder after division
392 196 0 (b0)
196 98 0 (b1)
98 49 0 (b2)
49 24 1 (b3)
24 12 0 (b4)
12 6 0 (b5)
6 3 0 (b6)
3 1 1 (b7)
1 0 1 (b8)
Binary-Decimal fraction conversion

• Binary to Decimal Conversion


– Sum-of-Weights method
– Weights decrease by a factor of 2
– 0.11012 weights ½, ¼, 1/16
– 0.5+0.25+0.0625
– Sum up to 0.8125
Binary-Decimal fraction conversion

• Decimal to Binary Conversion

– Repeated Multiplication by 2
Decimal-Binary fraction conversion

• Decimal to Binary Conversion


– Repeated multiplication by 2

Number Mult. By 2 Integer

0.8125 1.625 1 (b-1)


Decimal-Binary fraction conversion

• Decimal to Binary Conversion


– Repeated multiplication by 2

Number Mult. By 2 Integer

0.8125 1.625 1 (b-1)


0.625 1.250 1 (b-2)
Decimal-Binary fraction conversion

• Decimal to Binary Conversion


– Repeated multiplication by 2

Number Mult. By 2 Integer

0.8125 1.625 1 (b-1)


0.625 1.250 1 (b-2)
0.250 0.500 0 (b-3)
Decimal-Binary fraction conversion
• Decimal to Binary Conversion
– Repeated multiplication by 2

Number Mult. By 2 Integer

0.8125 1.625 1 (b-1)


0.625 1.250 1 (b-2)
0.250 0.500 0 (b-3)
0.500 1.000 1 (b-4)

(0.8125)10=(0.1101)2
Binary Arithmetic

• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Binary Division
Binary Addition
• Four Basic rules for binary addition

1st digit 2nd digit Sum Carry


0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
 Addition of multiple binary numbers
Binary Addition

Carry 1 1 10 1
1st Number 1 0 1 1
2nd Number 1 1 0
3rd Number 1 0 0 0
4th Number 1 1
Result 1 1 1 0 0
Binary Subtraction

• Four Basic rules for binary subtraction

1st digit 2nd digit Difference Borrow


0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Binary Subtraction

Borrow 1
1st Number 1 0 1 1
2nd Number 1 1 0
Result 1 0 1
Binary Multiplication

• Four Basic rules for binary multiplication

1st digit 2nd digit Product


0 0 0
0 1 0
1 0 0
1 1 1
 Example of Binary Multiplication
Binary Multiplication

1101 (13)
x 101 (5)
1st product term 1101
2nd product term 0000x
3rd product term 1101xx
Product 1000001 (65)
Multiplication by shifting left

• Decimal 29 shifted left by one digit


• 290
• Shift left 1 digit is multiply by 10

• Binary 111012 (29) shifted left by one bit


• 1110102 (58)
• Shift left 1 bit is multiply by 2
Binary Division(OPTIONAL)

10 2
101 | 1101 5 | 13
101
011 10
000 3
11
Binary Division(OPTIONAL)

10 11
11 | 110 10 | 110
110 10
0 10
10
0
Division by shifting right

• Decimal 29 shifted right by one digit


• 2.9
• Shift left 1 digit is divide by 10

• Binary 111012 (29) shifted left by one bit


• 1110.12 (14.5)
• Shift left 1 bit is divide by 2

You might also like