EE200 - DLD - Chapter 01

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 35

Digital Logic Design

Chapter 1
Numbers System
Recap: Analog Signal vs. Digital

Digital Logic Design - Chapter 1 2


Numbers
 Each number system is associated with a base or radix

 The decimal number system is said to be of base or radix 10

 A number in base r contains r digits 0,1,2,...,r-1


 Decimal (Base 10): 0,1,2,3,4,5,6,7,8,9

 Numbers are usually expressed in positional notation

An1 An2  A 1 A0.A1 A2  A  m  1 Am


 A number is expressed as a power series in r with the general
form
An1r n1  A n2r n2  A 1 0
r 1A r
1 r  A0 r  A 1 2
2

  Am1 rm1 Amr m

Digital Logic Design - Chapter 1 3


Numbers
An1 An2  A 1 A0.A1 A2  A  m  1 Am

 The . is called the radix point

 An1
: most significant digit (msd)

 Am : least significant d i g i t (lsd)


(724.5)10 724.5  7 102  2101  410 0  5101
1620.375  1103  610 2  2101  3101  7 102  510 3
2 1 0 1
(312.4)5  3 5 1 5  2 5  4 5  (82.8)10
In addition to decimal, three number systems are important: Binary, Octal, and

Hexadecimal

Digital Logic Design - Chapter 1 4


Decimal Number Representation
 Example: 90134 (base-10, used by Homo
Sapien)
 = 90000 + 0 + 100 + 30 + 4
 = 9*10 4 + 0*10 3 + 1*10 2 + 3*10 1 + 4*10 0
 How did we get it?

10 90134
10 9013 4
10 901 3
10 90 1
9
Digital Logic Design - Chapter 1
0 5
Generic Number Representation
 90134
 = 9*10 4 + 0*10 3 + 1*10 2 + 3*10 1 + 4*10 0
 A 4 A 3 A 2 A 1 A 0 for base-10 (or radix-10)

= A 4* 104 + A 3* 103 + A 2* 102 + A 1* 101 + A 0* 100
 (A is coefficient; b is base)
 Generalize for a given number N w / base-b
N = A n-1 A n-2 … A1 A0

N = A n-1* b n - 1 + A n-2* b n - 2 + … + A 2* b 2 + A 0* b 0
**Note that A < b

Digital Logic Design - Chapter 1 6


Decimal Review
 Numbers consist of a bunch of digits, each with a weight:

1 6 2 . 3 7 5 Digits
100 10 1 1/10 1/100 1/1000 Weights

 The weights are powers of the base, which is 10


1 6 2 . 3 7 5 Digits
102 101 100 10-1 10-2 10-3 Weights

 To find the decimal value of a number, multiply each digit by its


weight and sum the products

(1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375

Digital Logic Design - Chapter 1 7


Counting numbers with base-b

0 10 20 90 100 0 10 20 70
100
1 11 21 91 101 1 11 21 71
101
2 12 22 92 102 2 12 22 72
102
3 13 23 93 103 3 13 23 73
103
4 14 104 4 14 104
24 ….. 94 24 ….. 74
5 15 25 95 105 5 15 25 75 105
6 16 26 96 106 6 16 26 76 106
7 17 27 97 107 7 17 27 77 107
8 18 28 98 108
9 19 29 99 109

Base-10 How about Base-8

Digital Logic Design - Chapter 1 8


How about base-2

0 10 100 10 00
1 11 101 10 01
110 10 10
111 10 11

11 00
11 01
11 10
11 11

Digital Logic Design - Chapter 1 9


How about base-2

0 10 100 1000
1 11 101 1001
110 1010
111 1011
1100
1101
1110
1111

Digital Logic Design - Chapter 1 10


How about base-2

0=0 10 = 2 100 = 4 1000 = 8


1=1 11 = 3 101 = 5 1001 = 9
110 = 6 1010 = 10
111 = 7 1011 = 11
1100 = 12
1101 = 13
1110 = 14
1111 = 15

Binary = Decimal

Digital Logic Design - Chapter 1 11


Information Representation: Binary Numbers

 Radix = 2; Digits Ai can only take one of two


values (0 or 1)
 It is customary to refer to b inary dig it s as bit s

Digital Logic Design - Chapter 1 12


Number Examples with Different Bases
 Decimal (base-10)  Others examples:
 (982) 1 0  base-9 = (1321) 9
 Binary (base-2)  base-11 = (813) 11
 (01111010110) 2  base-17 = (36d) 1 7
 Octal (base-8)
 (1726) 8
 Hexadecimal (base-16)
 (3d6) 1 6

Digital Logic Design - Chapter 1 13


Convert between different bases

Convert a n u m b e r b a s e - x t o bas e- y, e.g. ( 0100111) 2 t o (?)6
 First, convert f r o m b a s e -x t o b a se -1 0 if x  1 0
 Then convert f r o m b a s e -1 0 t o base-y

0100111 = 026 + 125 + 024 + 023 + 122 + 121 + 120 = 39

6 39
6 6 3
1 0

 (0100111)2 = (103)6

Digital Logic Design - Chapter 1 14


Derive Numbers in Base-2
 Decimal (base-10)  Ex ercise
 (25) 1 0
 Binary (base-2) 2 25
 (11001) 2 2 12 1
2 6 0
2 3 0
1 1

Digital Logic Design - Chapter 1 15


Converting Binary to Decimal
 For example, here is
1101.01 in binary:
1 1 0 1 . 0 1
Bits Weights (in base 10)
23 22 21 20 2-1 2-2

2 1 0 : K(kilo); 2 2 0 : M (mega); 2 3 0 : G(giga )


 The decimal value is:
(1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) =

8 + 4 + 0 + 1 + 0 + 0.25 =
13.25

Digital Logic Design - Chapter 1 16


Converting Decimal to Binary
 To convert a decimal integer into binary, keep
dividing by 2 until the quotient is 0. Collect the
remainders in reverse order
 To convert a fraction, keep multiplying the fractional
part by 2 until it becomes 0. Collect the integer parts
in forward order
 Example: 162.375:
162 / 2 = 81 rem 0 0.375 x 2 = 0.750
81 / 2 = 40 rem 1 0.750 x 2 = 1.500
40 / 2 = 20 rem 0 0.500 x 2 = 1.000
20 / 2 = 10 rem 0
10 / 2 = 5 rem 0
5/2 =2 rem
1
2
1 // 22 = 0
1 rem rem 1
0
 So, (162.375) 10 = (10100010.011) 2
Digital Logic Design - Chapter 1 17
Why does this work?
 This works for converting from decimal to any
base
 Why? Think about converting 162.375 from
decimal to decimal
162 / 10 = 16 rem 2
16 / 10 = 1 rem 6
1 / 10 = 0 rem 1
 Each division strips off the rightmost
digit (the
remainder). The quotient represents the
remaining digits in the number
 Similarly, to convert fractions, each multiplication
strips off the leftmost digit (the integer part). The
fraction represents the remaining digits

0.375 x 10 = 3.750
0.750 x 10 = 7.500
0.500 x 10 = 5.000
Digital Logic Design - Chapter 1 18
Octal and Hexadecimal Numbers
 The octal number system: Base-8
 Eight digits: 0,1,2,3,4,5,6,7
(127.4)8  18 2  28 1  78 0  48  1  (87.5)10
 We use Base-16 (or Hex) a lot in computer world
 Sixteen digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
 Ex: A 3 2 - b i t address can be written as
 0xfe8a7d20 (0x is an abbreviation of Hex)
 Or in binary form 1111_1110_1000_1010_0111_1101_0010_0000

(B65F)  11163  616 2  5161 1516 0  (46687)


16
10

 For our purposes, base-8 and base-16 are most useful as a


“shorthand” notation for binary numbers

Digital Logic Design - Chapter 1 19


Numbers with Different Bases
Decimal Binary Octal Hex
0 0000 0 0
1 0001 1 1
2 0010 2 2
You can convert between base-10
3 0011 3 3
base-8 and base-16 using techniques
4 0100 4 4
like the ones we just showed for
5 0101 5 5
converting between decimal and
6 0110 6 6
binary
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

Digital Logic Design - Chapter 1 20


Binary and Octal Conversions
 Converting from octal to binary: Replace each octal digit with
its equivalent 3 - b i t binary sequence

(673.12)8 = 6 7 3 . 1 2
= 110 111 011 . 001
010
= (110111011.001010)2
 Converting from binary to octal: Make groups of 3
bits,starting from binary point. Add 0s to ends of number if
needed. Convert each bit group to its corresponding octal
digit. 10110100.0010112 = 010 110 100 . 001 0112
= 2 6 4 . 1 38

Octal Binary Octal Binary


0 000 4 100
1 001 5 101
2 010 6 110
3 011 7 111
Digital Logic Design - Chapter 1 21
Binary and Hex Conversions
 Converting from hex to binary: Replace each hex digit with its
equivalent 4 - b i t binary sequence
261.3516 = 2 6 1 .
516
3 = 0010 0110 0001 . 0011 01012
 Converting from binary to hex: Make groups of 4 bits, starting
from the binary point. Add 0s to the ends of the number if
needed. Convert each bit group to its corresponding hex digit
10110100.0010112 = 1011 0100 . 0010 11002
= B 4 . 2
C16

Hex Binary Hex Binary Hex Binary Hex Binary


0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111

Digital Logic Design - Chapter 1 22


Information Representation (cont.)
 Various Codes used in Computer Industry
 Number-only representation
 BCD (4 bits per decimal number)
 Alpha-numeric representation
 ASCII (7 bits)
 Unicode (16 bit)

Digital Logic Design - Chapter 1 23


Numeric Codes

Digital Logic Design - Chapter 1 24


Negative Number Representation
 Options
 Sign-magnitude
 One’s Complement
 Two’s Complement (we use this in this course)

Digital Logic Design - Chapter 1 25


Sign-magnitude
 Use the most significant bit (MSB) +0 000
to indicate the sign +1 001
 0: positive, 1: negative
 Problem +2 010
 Representing zeros?
+3 011
 Do not work in computation
-3 111

-2 110

-1 101

-0 100

Digital Logic Design - Chapter 1 26


One’s Complement
 Complement (flip) each bit in a +0 000
binary number
+1 001
 Problem
 Representing zeros? +2 010
 Do not always work in
computation +3 011
 Ex: 111 + 001 = 000  Incorrect
!
-3 100
-2 101
-1 110
0 111

Digital Logic Design - Chapter 1 27


Two’s Complement
 Complement (flip) each bit in a
binary number and add 1,
with overflow ignored
 Work in computation perfectly

3 011 -3 101

One’s complement One’s complement

100 010

Add 1 Add 1

-3 101 3 011

Digital Logic Design - Chapter 1 28


Two’s Complement
 Complement (flip) each bit in a 0 000
binary number and adding 1, with
overflow ignored +1 001
 Work in computation perfectly -1 111
 We will use it in this course ! +2 010
-2 110
100
+3 011
One’s complement
-3 101
011
The same 100 represents
Add 1 both 4 and -4 ?? 100
which is no good
100

Digital Logic Design - Chapter 1 29


Two’s Complement
 Complement (flip) each bit in a 0 000
binary number and adding 1, with
overflow ignored +1 001
 Work in computation perfectly -1 111
 We will use it in this course ! +2 010
-2 110
100
+3 011
One’s complement
-3 101
011
MSB = 1 for negative
Add 1 Number, thus 100 -4 100
represents -4
100

Digital Logic Design - Chapter 1 30


Range of Numbers
 An N - bit number
N
Unsigned: 0 .. (2 - 1 )
N- 1 N- 1
 Sig ned: -2 .. (2
- 1)
 Example: 4-bit

0000 (0) Unsigned numbers 1111 (15)

1000 (-8) 0111 (7)


Signed numbers

Digital Logic Design - Chapter 1 31


Binary Arithmetic

Digital Logic Design - Chapter 1 32


Binary Arithmetic: Multiplication

111.10 (7.5)1 0 = (111.10)2 Q3.2


10.1 (2.5)1 0 = (10.1)2 Q2.1
11110 (18.75) 1 0 = (10010.110)2 Q5.3
00000x
11110xx
10010110

Digital Logic Design - Chapter 1 33


Binary Computation

010001 (17=16+1)
001011 (11=8+2+1)

011100 (28=16+8+4)

Unsigned arithmetic Signed arithmetic (w/ 2’s complement)


010001 (17=16+1) 010001 (17=16+1)
101011 101011 (-21: 2’s
(43=32+8+2+1) complement=010101=21)

111100 111100 (2’s complement=000100=4,


(60=32+16+8+4) i.e. -4)

Digital Logic Design - Chapter 1 34


Binary Computation
Unsigned arithmetic
101111 (47)
The carry is 011111 (31)
discarded ---------------
001110 (78?? Due to overflow, note that
78 cannot be represented
by a 6-bit unsigned number)

Signed arithmetic (w/ 2’s complement)


101111 (-17 since 2’s complement=010001)
The carry is 011111 (31)
discarded ---------------
001110
(14)

Digital Logic Design - Chapter 1 35

You might also like