Uploaded by 20L145 - SUBERUS HEARTRISHA G

number systems and conversion

advertisement
Chapter 1 Number Systems and Codes
Chapter 1
1
Number Systems (1)
•
Positional Notation
N = (an-1an-2 ... a1a0 . a-1a-2 ... a-m)r
(1.1)
where . = radix point
r = radix or base
n = number of integer digits to the left of the radix point
m = number of fractional digits to the right of the radix point
an-1 = most significant digit (MSD)
a-m = least significant digit (LSD)
•
Polynomial Notation (Series Representation)
N = an-1 x rn-1 + an-2 x rn-2 + ... + a0 x r0 + a-1 x r-1 ... + a-m x r-m
n 1
=  ai r i
(1.2)
i  m
•
N = (251.41)10 = 2 x 102 + 5 x 101 + 1 x 100 + 4 x 10-1 + 1 x 10-2
Chapter 1
2
Number Systems (2)
•
Binary numbers
– Digits = {0, 1}
– (11010.11)2 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 1 x 2-2
= (26.75)10
– 1 K (kilo) = 210 = 1,024, 1M (mega) = 220 = 1,048,576,
1G (giga) = 230 = 1,073,741,824
•
Octal numbers
– Digits = {0, 1, 2, 3, 4, 5, 6, 7}
– (127.4)8 = 1 x 82 + 2 x 81 + 7 x 80 + 4 x 8-1 = (87.5)10
•
Hexadecimal numbers
– Digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
– (B65F)16 = 11 x 163 + 6 x 162 + 5 x 161 + 15 x 160 = (46,687)10
Chapter 1
3
Number Systems (3)
•
Important Number Systems (Table 1.1)
Decimal
0
1
2
3
5
6
7
8
9
10
11
12
13
14
15
16
Chapter 1
Binary
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
Octal
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
1
20
Hexadecimal
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
4
Arithmetic (1)
•
Binary Arithmetic
– Addition
111011 Carries
101011 Augend
+ 11001 Addend
1000100
– Subtraction
0 1 10 0 10
1 0 0 1 0
1 1 0 1
1 0 1
Chapter 1
Borrows
1 Minuend
1 Subtrahend
0
5
Arithmetic (2)
– Multiplication
x
1
0 0
1 1 0
1 1
1
0 0
1 0
0 0
1 0
0
0
0
1
0
1 0
1 0
0 0
0
1 0 0 0 0 0 1 0 0
Chapter 1
Division
Multiplicand
Multiplier
110
Divider 1 0 0 1 1 1 1 1 0 1
1001
1100
1001
111
Quotient
Dividend
Remainder
Product
6
Arithmetic (3)
•
Octal Arithmetic (Use Table 1.4)
–
Addition
1 1 1
Carries
5 4 7 1 Augend
+ 3 7 5 4 Addend
11445 Sum
– Subtraction
6 10
7 4
- 5 6
1 6
Chapter 1
4 10
5 1
4 3
0 6
Borrows
Minuend
Subtrahend
Difference
7
Arithmetic (4)
– Multiplication
326
x
67
2732
2404
26772
Chapter 1
Multiplicand
Multiplier
Partial products
Product
Division
Divider
114
63 7514
63
114
63
364
314
50
Quotient
Dividend
Remainder
8
Arithmetic (5)
•
Hexadecimal Arithmetic (Use Table 1.5)
– Addition
1 0
5
+ D
1 2
1
B
0
C
1
A 9
5 8
0 1
Carries
Augend
Addend
Sum
– Subtraction
+
Chapter 1
9 10
A 5
5 8
4 D
A 10
B 9
0 D
A C
Borrows
Minuend
Subtrahend
Difference
9
Arithmetic (6)
– Multiplication
B9A5
x D50
3A0390
96D61
9A76490
Chapter 1
Multiplicand
Multiplier
Partial products
Product
Division
Divider
79B
B9 57F6D
50F
706
681
85D
7F3
6A
Quotient
Dividend
Remainder
10
Base Conversion (1)
•
Series Substitution Method
– Expanded form of polynomial representation:
N = an-1rn-1 + … + a0r0 + a-1r-1 + … + a-mr-m
(1.3)
– Conversation Procedure (base A to base B)
• Represent the number in base A in the format of Eq. 1.3.
• Evaluate the series using base B arithmetic.
– Examples:
• (11010)2 ( ? )10
N = 124 + 123 + 022 + 121 + 020
= (16)10 + (8)10 + 0 + (2)10 + 0
= (26)10
• (627)8  ( ? )10
N = 682 + 281 + 780
= (384)10 + (16)10 + (7)10
= (407)10
Chapter 1
11
Base Conversion (2)
•
Radix Divide Method
– Used to convert the integer in base A to the equivalent base B integer.
– Underlying theory:
• (NI)A = bn-1Bn-1 + … + b0B0
(1.4)
Here, bi’s represents the digits of (NI)B in base A.
• NI / B  (bn-1Bn-1 + … + b1B1 + b0B0 ) / B
= (Quotient Q1: bn-1Bn-2 + … + b1B0 ) + (Remainder R0: b0)
• In general, (bi)A is the remainder Ri when Qi is divided by (B)A.
– Conversion Procedure
1. Divide (NI)B by (B)A, producing Q1 and R0. R0 is the least significant
digit, d0, of the result.
2. Compute di, for i = 1 … n - 1, by dividing Qi by (B)A, producing Qi+1
and Ri, which represents di.
3. Stop when Qi+1 = 0.
Chapter 1
12
Base Conversion (3)
– Examples
• (315)10 = (473)8
8 315
8 39
8 4
0
3
7
4
LSD
MSD
• (315)10 = (13B)16
16 315
16 19
16 1
0
Chapter 1
B
3
1
LSD
MSD
13
Base Conversion (4)
•
Radix Multiply Method
– Used to convert fractions.
– Underlying theory:
• (NF)A = b-1B-1 + b-2B-2 + … + b-mB-m
(1.5)
Here, (NF)A is a fraction in base A and bi’s are the digits of (NF)B in
base A.
• B  NF = B  (b-1B-1 + b-2B-2 + … + b-mB-m )
= (Integer I-1: b-1) + (Fraction F-2: b-2B-1 + … + b-mB-(m-1))
• In general, (bi)A is the integer part I-i, of the product of F-(i+1)  (BA).
– Conversion Procedure
1. Let F-1 = (NF)A.
2. Compute digits (b-i)A, for i = 1 … m, by multiplying Fi by (B)A,
producing integer I-i, which represents (b-i)A, and fraction F-(i+1).
3. Convert each digits (b-i)A to base B.
Chapter 1
14
Base Conversion (5)
– Examples
• (0.479)10 = (0.3651…)8
MSD 3.832  0.479  8
6.656  0.832  8
5.248  0.656  8
LSD
1.984  0.248  8
…
• (0.479)10 = (0.0111…)2
MSD 0.9580  0.479  2
1.9160  0.9580  2
1.8320  0.9160  2
LSD
1.6640  0.8320  2
…
Chapter 1
15
Base Conversion (6)
•
•
General Conversion Algorithm
Algorithm 1.1
To convert a number N from base A to base B, use
(a) the series substitution method with base B arithmetic, or
(b) the radix divide or multiply method with base A arithmetic.
•
Algorithm 1.2
To convert a number N from base A to base B, use
(a) the series substitution method with base 10 arithmetic to convert N
from base A to base 10, and
(b) the radix divide or multiply method with decimal arithmetic to convert
N from base 10 to base B.
•
Algorithm 1.2 is longer, but easier and less error prone.
Chapter 1
16
Base Conversion (7)
•
Example
(18.6)9 = ( ? )11
(a) Convert to base 10 using series substitution method:
N10 = 1  91 + 8  90 + 6  9-1
= 9 + 8 + 0.666…
= (17.666…)10
(b) Convert from base 10 to base 11 using radix divide and multiply
method:
7.326  0.666  11
11 17 6
11 1 1
3.586  0.326  11
0
6.446  0.586  11
.
N11 = (16.736 …)11
Chapter 1
17
Base Conversion (8)
•
•
When B = Ak
Algorithm 1.3
(a) To convert a number N from base A to base B when B = Ak and k is a
positive integer, group the digits of N in groups of k digits in both directions
from the radix point and then replace each group with the equivalent digit in
base B
(b) To convert a number N from base B to base A when B = Ak and k is a
positive integer, replace each base B digit in N with the equivalent k digits in
base A.
•
Examples
– (001 010 111. 100)2 = (127.4)8 (group bits by 3)
– (1011 0110 0101 1111)2 = (B65F)16 (group bits by 4)
Chapter 1
18
Download