Professional Documents
Culture Documents
Chapter 1 Number Systems and Codes
Chapter 1 Number Systems and Codes
Chapter 1
Positional Notation
N = (an-1an-2 ... a1a0 . a-1a-2 ... a-m)r
(1.1)
i
=
i m
(1.2)
Chapter 1
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
Binary
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
Chapter 1
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
Arithmetic (1)
Binary Arithmetic
Addition
111011Carries
101011Augend
+11001Addend
1000100
Subtraction
0110010Borrows
100101Minuend
11011Subtrahend
1010
Chapter 1
Arithmetic (2)
Multiplication
11010Multiplicand
x1010Multiplier
00000
11010
00000
11010
Division
Divider
1001
110
Quotient
Dividend
111
Remainder
111101
1001
1100
1001
100000100Product
Chapter 1
Arithmetic (3)
Addition
111Carries
5471Augend
+3754Addend
11445Sum
Subtraction
610410Borrows
7451Minuend
5643Subtrahend
1606Difference
Chapter 1
Arithmetic (4)
Multiplication
326Multiplicand
Divider
x67Multiplier
2732Partialproducts
2404
26772Product
Chapter 1
Division
63
114
7514
63
114
63
364
314
50
Quotient
Dividend
Remainder
Arithmetic (5)
1011Carries
5BA9Augend
+D058Addend
12C01Sum
Subtraction
910A10Borrows
A5B9Minuend
+580DSubtrahend
4DACDifference
Chapter 1
Arithmetic (6)
Multiplication
B9A5Multiplicand
xD50Multiplier
3A0390Partialproducts
96D61
9A76490Product
Chapter 1
Division
Divider
B9
79B
57F6D
50F
706
681
85D
7F3
6A
Quotient
Dividend
Remainder
10
Chapter 1
11
Chapter 1
12
315
8 39
8 4
0
3
7
4
LSD
MSD
(315)10 = (13B)16
16
315
16 19
16 1
0
B
3
1
Chapter 1
LSD
MSD
13
(1.5)
Here, (NF)A is a fraction in base A and bis 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
LSD
3.832 0.479 8
6.656 0.832 8
5.248 0.656 8
1.984 0.248 8
(0.479)10 = (0.0111)2
MSD
LSD
0.9580 0.479 2
1.9160 0.9580 2
1.8320 0.9160 2
1.6640 0.8320 2
Chapter 1
15
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.
Chapter 1
16
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 1111 17
6
3.586 0.326 11 11 1
1
0
6.446 0.586 11
Chapter 1
17
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
(1.6)
Chapter 1
19
Chapter 1
20
The same rule applies to the case when N contains a radix point.
Chapter 1
21
Chapter 1
22
where 0 N 2 1.
Negative number:
N = (an-1, an-2, ..., a0)2
-N = [an-1, an-2, ..., a0]2 (two's complement of N),
n 1
where 1 N 2 .
Chapter 1
23
Chapter 1
24
Chapter 1
25
Case 1: A = B + C
(A)2 = (B)2 + (C)2
If A > 2n-1 -1 (overflow), it is detected by the nth bit, which is set to 1.
Example: (7)10 + (4)10 = ? using 5-bit twos complement arithmetic.
+ (7)10 = +(0111)2 = (0, 0111)2cns
+ (4)10 = +(0100)2 = (0, 0100)2cns
(0, 0111)2cns + (0, 0100)2cns = (0, 1011)2cns = +(1011)2 = +(11)10
No overflow.
Example: (9)10 + (8)10 = ?
+ (9)10 = +(1001)2 = (0, 1001)2cns
+ (8)10 = +(1000)2 = (0, 1000)2cns
(0, 1001)2cns + (0, 1000)2cns = (1, 0001)2cns (overflow)
Chapter 1
26
Case 2: A = B - C
A = (B)2 + (-(C)2) = (B)2 + [C]2 = (B)2 + 2n - (C)2 = 2n + (B - C)2
If B C, then A 2n and the carry is discarded.
So, (A)2 = (B)2 + [C]|carry discarded
If B < C, then A = 2n - (C - B)2 = [C - B]2 or A = -(C - B)2 (no carry in this
case).
No overflow for Case 2.
Example: (14)10 - (9)10 = ?
Perform (14)10 + (-(9)10)
(14)10 = +(1110)2 = (0, 1110)2cns
-(9)10 = -(1001)2 = (1, 0111)2cns
(14)10 - (9)10 = (0, 1110)2cns + (1, 0111)2cns = (0, 0101)2cns + carry
= +(0101)2 = +(5)10
Chapter 1
27
Chapter 1
28
Case 3: A = -B - C
A = [B]2 + [C]2 = 2n - (B)2 + 2n - (C)2 = 2n + 2n - (B + C)2 = 2n + [B + C]2
The carry bit (2n) is discarded.
An overflow can occur, in which case the sign bit is 0.
Example: -(7)10 - (8)10 = ?
Perform (-(7)10) + (-(8)10)
-(7)10 = -(0111)2 = (1, 1001)2cns , -(8)10 = -(1000)2 = (1, 1000)2cns
-(7)10 - (8)10 = (1, 1001)2cns + (1, 1000)2cns = (1, 0001)2cns + carry
= -(1111)2 = -(15)10
Example: -(12)10 - (5)10 = ?
Perform (-(12)10) + (-(5)10)
-(12)10 = -(1100)2 = (1, 0100)2cns , -(5)10 = -(0101)2 = (1, 1011)2cns
-(7)10 - (8)10 = (1, 0100)2cns + (1, 1011)2cns = (0, 1111)2cns + carry
Overflow, because the sign bit is 0.
Chapter 1
29
Chapter 1
30
Summary
Case
B+C
B-C
-B - C
Carry
0
0
1
0
1
1
Sign Bit
0
1
0
1
1
0
Condition
B + C 2n-1 - 1
B + C > 2n-1 - 1
B C
B>C
-(B + C) -2n-1
-(B + C) < -2n-1
Overflow ?
No
Yes
No
No
No
Yes
Chapter 1
31
(1.10)
(1.11)
Chapter 1
32
Chapter 1
33
Chapter 1
34
Chapter 1
35
Numeric Codes
To represent numbers.
Fixed-point and floating-point number.
Fixed-point Numbers
Used for signed integers or integer fractions.
Sign magnitude, twos complement, or ones complement systems are
used.
Integer: (Sign bit) + (Magnitude) + (Implied radix point)
Fraction: (Sign bit) + (Implied radix point) + (Magnitude)
Chapter 1
36
Chapter 1
37
N = M rE, where
M (mantissa or significand) is a significant digits of N
E (exponent or characteristic) is an integer exponent.
n 1
m r
Chapter 1
(1.13)
(1.14)
(1.15)
38
(1.16)
(1.17)
e 1
(1.18)
Chapter 1
39
(1.19)
(1.20)
(1.21)
Example: M = +(1101.0101)2
M = +(1101.0101)2
= (0.11010101)2 24
(1.22)
= (0.011010101)2 25
(1.23)
= (0.0011010101)2 26
(1.24)
Chapter 1
40
Exponent E
Mantissa M
Sign of mantissa
Exponent E
Chapter 1
41
Chapter 1
42
Chapter 1
43
Chapter 1
Binary Code
1000100
1101001
1100111
1101001
1110100
1100001
1101100
Hexadecimal Code
44
69
67
69
74
61
6C
44
Gray Code
Cyclic code: A circular shifting of a code word produces another code
word.
Gray code: A cyclic code with the property that two consecutive code
words differ in only 1 bit (the distance between the two code words is 1).
Gray code for decimal numbers 0 - 15: See Table 1.12
Chapter 1
45
Chapter 1
46
General Properties
Minimum distance, dmin, of a code C: for any two code words I and J in C,
d(I, J) dmin
A code provides t error correction plus detection of s additional errors if
and only if the following inequality is satisfied.
2t + s + 1 dmin
(1.25)
Example:
Single-error detection (SED): s = 1, t = 0, dmin = 2.
Single-error correction (SEC): s = 0, t = 1, dmin = 3.
Single-error correction and double-error detection (SEC and DED):
s = t = 1, dmin = 4.
Chapter 1
47
Errorword
Validcodeword
d min =2
(a)SED
d min =4
(c)(SECandDED)orTED
Chapter 1
d min =3
(b)SECorDED
d min =5
(d)DEC,(SECand3ED),or4ED
48
Informationbits
Paritybit
Chapter 1
Information
tracks
Paritytrack
49
ASCII Code
Odd-parity Code
0110000
10110000
1011000
01011000
0111100
1111100
BEL
0000111
00000111
Error detection: Check whether a code word has the correct parity.
Single-error detection code (dmin = 2).
Two-out-of-Five Code
Each code word has exactly two 1s and three 0s.
Detects single errors and multiple errors in adjacent bits.
Chapter 1
50
Chapter 1
51
1000111
0100110
0010101
0001011
0001
p
p
p
41 42 43
(1.26)
Chapter 1
52
(1.28)
1110100
1101010
1011001
Chapter 1
53
Chapter 1
54
10000111
01001110
G
00101101
00011011
(1.33)
01111000
11100100
H
11010010
10110001
(1.34)
Odd-weight-column code:
H matrix has an odd number of ones in each column.
Example: Hamming Code 2.
Has many properties; single-error correction, double-error detection,
multiple-error detection, low cost encoding and decoding, etc.
Chapter 1
55
H
110110100110010
101110011010001
Chapter 1
(1.35)
56
H
110110010
101110001
Chapter 1
(1.36)
100001111
010001110
G 001001101
000101011
000010111
(1.37)
57