SlideShare a Scribd company logo
1 of 106
Download to read offline
Digital Electronics
Chapter 2: Number systems and codes
Number systems
Why do people think of decimal codes?
Why do people think binary code?
Why do people
think of
quadratic
codes?
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
= (1.2)
◼ N = (251.41)10 = 2 x 102 + 5 x 101 + 1 x 100 + 4 x 10-1 + 1 x 10-2
a r
i
i
i m
n
=−
−

1
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
Chapter 1
5
Number Systems (3)
◼ 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
Number Systems (3)
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
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.
Number Systems (4)
◼ Base Conversion
Convert decimal to binary Convert binary to decimal
Base Conversion (4)
Examples
◼ (315)10 = (473)8
◼ (315)10 = (13B)16
315
8
39
8
4
8
0
3
7
4
LSD
MSD
315
16
19
16
1
16
0
B
3
1
LSD
MSD
Base Conversion (5)
◼ 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.
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
13
Base Conversion (6)
◼ 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)
Base Conversion (6)
◼ Question: How to convert octal
and hexadecimal to binary and
vice versa?
Problems
Problems
Arithmetic (1)
◼ Binary Arithmetic
 Addition
111011 Carries
101011 Augend
+ 11001 Addend
1000100
 Subtraction
0 1 10 0 10 Borrows
1 0 0 1 0 1 Minuend
- 1 1 0 1 1 Subtrahend
1 0 1 0
Arithmetic (2)
◼ Performs the following binary
operations::
1 1 0 1 1
+ 1 0 1 0
Result?
1 0 0 0 1 0 0
- 1 0 1 0 1 1
Result?
1 0 0 1 0 0
- 1 1 0 1 1
Result?
19
Arithmetic (3)
Multiplication
1 1 0 1 0 Multiplicand
x 1 0 1 0 Multiplier
0 0 0 0 0 Partial products
1 1 0 1 0
0 0 0 0 0
1 1 0 1 0
1 0 0 0 0 0 1 0 0 Product
Arithmetic (4)
Division
Quotient
Divider
Remainder
Dividend
Arithmetic (5)
Application of shift register in
multiplication and division by 2
Problems
Signed Number Representation
◼ Signed Magnitude Method
 N = ± (an-1 ... a0.a-1 ... a-m)r is represented as
N = (san-1 ... a0.a-1 ... a-m)rsm,
where s = 0 if N is positive and s = r -1 otherwise.
 N = -(15)10
 In binary: N = -(15)10 = -(1111)2 = (1, 1111)2sm
 In decimal: N = -(15)10 = (9, 15)10sm
Complementary Number Systems (1)
◼ Complementary Number Systems
 Radix complements (r's complements)
[N]r = rn - (N)r
where n is the number of digits in (N)r.
 Diminished radix complements (r-1’s complements)
[N]r-1 = rn - (N)r - 1
Radix Complement Number Systems (2)
◼ Two's complement of (N)2 = (101001)2
[N]2 = 26 - (101001)2 = (1000000)2 - (101001)2 = (010111)2
◼ (N)2 + [N]2 = (101001)2 + (010111)2 = (1000000)2
If we discard the carry, (N)2 + [N]2 = 0.
Hence, [N]2 can be used to represent -(N)2.
◼ [ [N]2 ]2 = [(010111)2]2 = (1000000)2 - (010111)2 = (101001)2 = (N)2.
◼ Two's complement of (N)2 = (1010)2 for n = 6
[N]2 = (1000000)2 - (1010)2 = (110110)2.
◼ Ten's complement of (N)10 = (72092)10
[N]10 = (100000)10 - (72092)10 = (27908)10.
Radix Complement Number Systems (3)
◼ Algorithm Find [N]r given (N)r .
 First replace each digit, ak , of (N)r by (r - 1) - ak and then add 1 to the
resultant.
◼ For binary numbers (r = 2), complement each digit and add 1 to the result.
◼ Example: Find 2’s complement of N = (01100101)2 .
N = 01100101
10011010 Complement the bits
+1 Add 1
[N]2 = (10011011)10
◼ Example: Find 10’s complement of N = (40960)10
N = 40960
59039 Complement the bits
+1 Add 1
[N]2 = (59040)10
27
Radix Complement Number Systems (4)
◼ Two's complement number system:
 Positive number :
◼ N = +(an-2, ..., a0)2 = (0, an-2, ..., a0)2cns,
where .
 Negative number:
◼ N = (an-1, an-2, ..., a0)2
◼ -N = [an-1, an-2, ..., a0]2 (two's complement of N),
where .
 Example: Two's complement number system representation of ± (N)2
when (N)2 = (1011001)2 for n = 8:
◼ +(N)2 = (0, 1011001)2cns
◼ -(N)2 = [+(N)2]2 = [0, 1011001]2 = (1, 0100111)2cns
−   − −
1 2 1
N n
0 2 1
1
  −
−
N n
Radix Complement Number Systems (5)
◼ Example: Two's complement number system representation
of -(18)10 , n = 8:
 +(18)10 = (0, 0010010)2cns
 -(18)10 = [0, 0010010]2 = (1, 1101110)2cns
◼ Example: Decimal representation of N = (1, 1101000)2cns
 N = (1, 1101000)2cns = -[1, 1101000]2 = -(0, 0011000)2cns
= -(24)2
Problems
Problems
Fixed point number
± 0 1 1 0 0 1 0 0 1
Sign
Integer bits
Radix
point
Fixed point number: There is a fixed position separating the integer
and fractional parts.
Problem: can't decide how many bits for integer and fraction are
appropriated
Fractional bits
Floating point number
± 0 1 1 1 0 0 1 1 1
E
(Exponent)
m
(Mantissa)
Sign
bit
Floating Point Numbers (1)
◼ N = M ´ rE, where
 M (mantissa or significand) is a significant digits of N
 E (exponent or characteristic) is an integer exponent.
◼ In general, N = ± (an-1 ... a0 .a-1 ... a-m)r is represented by
 N = ± (.an-1 ... a-m)r ´ rn
◼ M is usually represented in sign magnitude:
 M = (SM.an-1 ... a-m)rsm , where
 (.an-1 ... a-m)r represents the magnitude
 SM = (0: positive, 1: negative)
( ) (. ... )
−  − −
1 1
S
n m r
M
a a
Floating Point Numbers (1)
Some common floating point number format
Floating Point Numbers (1)
Some common floating point number format
Floating Point Numbers (1)
Floating point number
Số dấu chấm động có dạng:
S E M
B1: Chuyển đổi số trên ra hệ hai
-2345,125 = -1001 0010 1001.001
B2: Chuẩn hoá theo IEEE 32bit
-1001 0010 1001.001
=> -1.001 0010 1001 001 x 2^11
B3: Xác định các thông số biểu diễn S,E,M
S: phần định trị là số âm, nên S là 1
E : phần mũ được xác định là 8 bit E = 11+127=138=10001010
M: phần định trị được xác định là 001 0010 1001 0010 0000 0000 (23 bit)
Dãy số là:
S E M
1 10001010 00100101001001000000000
IEEE 32bit
Biểu diễn số 23 trong hệ 10 theo chuẩn Chuẩn IEEE-754 32 bit
(23)10 = (10111)2 = 1.0111e + 0100.
• Sau dấu phẩy= 0111000 00000000 00000000.
• Số mũ = 00000100.
• Tính phần bù số mũ = 00000100 + 01111111 = 10000011.
• Bit dấu là dương vì vậy nó sẽ là = 0.
• (+23)10 = 01000001 10111000 00000000 00000000.
• (–23)10= 11000001 10111000 00000000 00000000
Floating Point Numbers (1)
Biểu diễn số -124 trong hệ 10 theo chuẩn Chuẩn IEEE-754 64 bit
• Chuyển số (124)10 sang hệ nhị phân (124)10 = (10001110)2.
• (10001110)2 = 1.000 1110 × 27 = 1.0001110e + 0111.
• Số mũ = 00000000111.
• Phần bù của số mũ = 00000000111 + 01111111111 = 00010000110.
• Sau dấu phẩy = 0001110 00000000 00000000.
• Dấu của số số = 1.
• Vì vậy, (-124)10 = 11000011 00001110 00000000 00000000.
Xác định số thập phân tương đương cho các số dấu phẩy động sau:
00111111 01000000 00000000 00000000 (chuẩn IEEE-754 32 bit);
00111111 01000000 00000000 00000000 (chuẩn IEEE-754 32 bit);
Bit đầu tiên của số là 0 => số dương
Phần bù của số mũ là: 0111111 0
Tách phần số mũ = 0111111 0 – 01111111 = 11111111 (số âm)
Vì 0111111 0 < 01111111
Chuyển phần số mũ sang số dương: 00000001 => phần mũ của số là – 00000001
Phần sau dấu phẩy: 1000000 00000000 00000000 => 1.1000000 00000000 00000000
Vì số mũ của số là -00000001=-1 => Phần sau dấu phẩy là:
1.1000000 00000000 00000000 => 0.11000000 00000000 00000000
Số cần tìm là: (0.11)2=(0.75)10
Xác định số thập phân tương đương cho các số dấu phẩy động sau:
11000000 00101001 01100 … 45 số 0 (theo chuẩn IEEE-754 64 bit).
11000000 00101001 01100 … 45 số 0 (theo chuẩn IEEE-754 64 bit).
Bit đầu tiên của số là 1 => số âm
Phần bù của số mũ là: 1000000 0010
Tách phần số mũ = 1000000 0010 – 01111111111 = 00000000011 = (3)10
Phần sau dấu phẩy: 1001 01100 … 45 số 0 => 1.100101 01100 … 45 số 0
Vì số mũ của số là 3 => Phần sau dấu phẩy là:
1.100101 01100 … => 1100.101 01100
Số cần tìm là: (- 1100.101 011)2=(-12.625)10
Problems:
Represent the following in the IEEE-754 floating-point
standard using the single-precision format:
1. (−118.625)10
2. (118.015)10
3. (−412.623)10
4. (512.128)10
Convert following floating-point standard single-precision
binary to decimal number
1. 11110000 11001100 10101010 00001111
2. 01110011 11101100 10101010 00000000
3. 10110000 11001100 11111110 00001100
4. 01111110 11001100 10101011 00000000
Coding
Assume that you want to communicate with
your friend with a flashlight in a night, what
will you do?
What is the problem?
Drawing the word?
Coding
Solution #1
•A: 1 blink
•B: 2 blinks
•C: 3 blinks
:
•Z: 26 blinks
What’s the problem?
•How are you? = 131 blinks
Coding
Solution #2 - Morse code
Hello
Lookup
•It is easy to translate into Morse
code than reverse. Why?
Tra mã hóa (Lookup)
Số của mã = 2số chấm và số gạch
Tại sao lại phải dùng . và -?
Tra mã hóa (Lookup)
Useful for
checking the
correctness/
redundency
Mã hóa (Lookup) – Braille
Louis Braille Braille code
Tra mã hóa (Lookup)
Braille
Tra mã hóa (Lookup)
Braille
Morse
Both of these
encodings are binary
Binary representations
•Electronic Implementation
–Easy to store with bistable elements
–Reliably transmitted on noisy and inaccurate wires
0 0
3.3V
2.8V
0.5V
0.0V
1
Why encryption?
Today's digital computers only understand the
numbers 0 and 1, so any information in the
form of digits, letters, characters ... must be
converted to binary form
Coding areas
Coding areas include:
- Decimal encoding
- Character encoding
- Script encoding
- Voice coding
- Image encoding
- …
BCD – Binary coded
4 bits are
required to
encode decimal
numbers
Bitcoin Code Diamond
BCD – Binary coded decimal
• Weighted BCD code
• Non-weighted BCD code
(excess-3, gray, ASCII)
Category:
BCD – Binary coded decimal
• A weighted BCD code is one that allows analysis into
polynomials according to its weight.
• Weighted BCD codes are divided into two types of codes:
- Natural BCD Code: A code in which the weights are
usually arranged in ascending order
Example: BCD 8421, BCD 5421
- Arithmetic BCD code; A code that is symmetric through a
middle path
Example : BCD 2421, BCD 5121, BCD8 4-2-1
BCD – Binary coded decimal
◼ BCD is used to represent information such as strings of letters or
numbers
◼ Each position has a weight
◼ BCD Codes:
0: 0000 1: 0001 2: 0010 3: 0011 4: 0100
5: 0101 6: 0110 7: 0111 8: 1000 9: 1001
 Example: (9750)10 = (1001 0111 0101 0000)BCD
BCD – Binary coded decimal
BCD – Binary coded decimal
Đối
xứng
nhau
Arithmetic BCD code
BCD – Binary coded decimal
BCD – Binary coded decimal
BCD – Binary coded decimal
BCD 8421 code recognition circuit:
There will be no number
where a3 and a1 or a3 and
a2 are equal to 1
y = 1 Not BCD
y = 0 BCD
BCD – Binary coded decimal
Mạch nhận dang mã BCD 8421:
There will be no number where a3 and a1
or a3 and a2 are equal to 1
y = Not BCD
y = 0 BCD
Gray code
Gray-coded disk
Các phép tính trên số BCD
Do số BDC chỉ có giá trị từ 0->9 nên đối với những số thập phân lớn hơn sẽ
chia số thập phân thành các phần, mỗi phần được biểu diễn bởi 1 số BCD
tương ứng:
Các phép tính trên số BCD
Phép trừ tính trên số BCD theo quy tắc sau:
A – B = A + B’ trong đó B’ là phần bù của B
BCD advantages and disadvantages
ASCII
◼ ASCII (American Standard Code for Information Interchange)
Character sets
Standard ASCII(0 – 127)
Extended ASCII (0 – 255)
◼ – ANSI (0 – 255)
◼ – Unicode (0 – 65,535)
Character BCD Decimal
D 1000100 44
i 1101001 69
g 1100111 67
i 1101001 69
t 1110100 74
a 1100001 61
l 1101100 6C
ASCII
Assignment
Bài tập 1:
Chuyển đổi các số thập phân sau sang hệ nhị phân, bat phân và thập lục phân:
9210, 14410, 40910, 25410, 25610, 6452210
Bài tập 2:
Chuyển đổi các số sau sang số bù nhị phân 8 bit: -110, -510, -1710, -6410, -12810,
2510.
Bài tập 3:
Thực hiện phép tính số học sau bằng phương pháp trừ nhị phân và sử dụng
số bù 2: 6110 - 1710 = ?
Bài tập 4:
Biểu diễn các số thập phân sau bằng mã nhị phân vầ mã BCD(2421): 1610 và
199910
Error Detection and
Correction code
7
2
Error detection/correction code: Information is encoded in such a
way that a particular class of errors can be detected and/or corrected.
Contents
• Concept
• Hamming code
• CRC check
Concepts
◼ An error: An incorrect value in one or more bits.
◼ Single error: An incorrect value in only one bit.
◼ Multiple error: One or more bits are incorrect.
◼ Errors are introduced by hardware failures, external interference (noise), or
other unwanted events.
Concepts
• Error detection rule: If only transmitting the correct
data to be transmitted, the error cannot be detected
Need to send more information with the data
 Information attached to help detect errors
• Method: Mã khối – Block coding
Split the data into k-bit blocks and convert to n-bit
blocks, where n = k +r
=> Error detection and correction is done at the Data link
layer
76
Concepts
• Example: Vertical Redundancy Check (VRC) technique
Add a bit to the end of the data block, according to the rule: "Total
number of 1's is even“
The extra bit is called Parity Check.
Example: check even
0110011 → 01100110
0110001 → 01100011
Comment: Only odd number of errors detected
// bit thêm vào là 0 để tổng số bit 1 là chẵn
// bit thêm vào là 1 để tổng số bit 1 là chẵn
Concepts
• Model
77
Model
0110011
01100110 00100110
Thêm bit kiểm tra Check number of 1s
Lỗi
Data word
Code word
Example:
78
Add check bit
79
Method – Error detection
• To detect errors:
- The receiver has a list of correct code
words
- If the received code word is not in the
list -> there is an error
=> Comment: only detect errors according to the
preset design
Example:
Word code table for error detection
• Code word (code word) has an even number of 1’s
• Codewords do not overlap, differ by 2 bits
80
Hamming distance
• Khoảng cách Hamming giữa 2 từ cùng độ dài : là số bit
(ở cùng vị trí ) khác nhau
• Khoảng cách Hamming tối thiểu : là khoảng cách nhỏ
nhất giữa 2 cặp bất kỳ có trong một tập từ.
Ví du: d(000, 011) là 2 Vì
81
Khoảng cách Hamming
dmin trong bảng sau là 2
82
83
Khoảng cách Hamming
• Định lý 1 : Để đảm bảo phát hiện lỗi của s bit
thì khoảng cách Hamming cực tiểu trong các
cặp từ mã phải là dmin = s+1
• Định lý 2: để sửa t lỗi , khoảng cách Hamming
cực tiểu trong các từ mã phải là
dmin = 2t +1
84
Mã Hamming
• Dùng để sửa lỗi
• Mã Hamming xem xét trong bài này có
dmin = 3
=> Theo định lý 2: dùng để sửa 1 lỗi
Cấu trúc của bộ mã hóa và bộ giải mã Hamming C(7,4)
85
Cho bảng mã Hamming C(7,4)
86
Mã Hamming
87
r0=a2+a1+a0 module2
r1=a3+a2+a1 module2
r2=a0+a1+a3 module2
Ký hiệu :
Data word : a3 a2 a1 a0 1010
Code word : a3 a2 a1 a0 r2 r1 r0 1010001
Xác định code word <=> tính r2 r1 r0
Mã Hamming
Chuỗi bit nhận được cần kiểm tra : b3b2b1b0q2q1q0
(1)Tính syndrome: s2s1s0
(2)nếu s2s1s0 = 000 thì không có lỗi
ngược lại: =>có lỗi
s0=b2+b1+b0+q0 module 2 = 1 % 2 = 1
s1=b3+b2+b1+q1 module 2 = 1 %2 = 1
s2=b0+b1+b3+q2 module 2 =(0+0+1+0)%2 =1
88
Giải Mã Hamming
Logical decision made by the correction logic analyzer
Cách sửa lỗi :
(1)tìm bit bị lỗi dựa vào bảng dò lỗi sau
(2)đảo ngược bit lỗi
89
Sửa Lỗi Mã Hamming
90
Mã Hamming
•VD1 : Bên nhận nhận được code word 0100011 Xác định dataword?
Giải :
0100011: b0 = 0/ b1 = 0/ b2 =1/ b3 =0/ q0=1/ q1=1/q2=0
s0=b2+b1+b0+q0
s0=1+0+0+1 = 10 module 2 = 0
s1=b3+b2+b1+q1
s1= 0+1+0+1 = 10 module 2 = 0
s2=b0+b1+b3+q2
s2=0+0+0+0 = 0 module 2 = (0+0+0+0)%2=0
Tính syndrome s2s1s0= 000
Kết luận : Code word nhận được không lỗi
Data word là 4 bit cực trái: 0100
Mã Hamming
•VD2 : Bên nhận nhận được code word
0101011 Xác định data word ?
Giải :
Tính syndrome s2s1s0 = 101
(ghi chi tiết cách tính s2, s1, s0 … )
Kết luận : code word nhận được bị lỗi
Dựa theo bảng : bit lỗi là b0 Sửa bit b0
=> Data word là 4 bit cực trái : 0100
Mã Hamming
Bài tập:
Xác định lỗi nếu có và sửa lỗi dựa trên tín hiệu
nhận được sử dụng mã Hamming
Codeword: 0101010, 1111011, 0111011
93
Mã phát hiện lỗi
Cyclic Redundancy Check (CRC)
• CRC là một phương pháp để phát hiện lỗi
bằng cách gắn thêm một khối bit phía sau
khối dữ liệu
• Các bit bổ sung thêm vào gọi là các bit CRC
• Có một số phương pháp cài đặt : modulo 2,
đa thức, …
Mô hình mã và giải mã CRC
94
95
Mô hình mã và giải mã CRC
• Bên gửi :
– Đầu vào : Dataword 4 bit
– Dùng bộ mã để tính r2r1r0
• Bên nhận :
– Nhận Codeword 7 bit
=> thu được Codeword 7 bit
– Dùng bộ giải mã để tính Syndrome
• Nếu Syndrome ≠ 0 => một hoặc nhiều bit bị lỗi
• Nếu Syndrome = 0 : 2 trường hợp
– Không có lỗi => Thu được Dataword
– Một số bit bị lỗi , nhưng bộ giải mã không phát hiện được
96
Mô hình mã và giải mã CRC
• Bên gửi : thực hiện mã Dataword k bits (k= 4) => kết
quả thu được Codeword n bits (n= 7) => truyền Codeword
đi.
Quy trình mã hóa với Dataword k =4bit, Codeword n =7:
(1)Thêm vào bên phải Dataword số bit 0 là n-k (3 bit)
(2)Một số chia xác định trước d3d2d1d0, có số bit n-k+1
Ví dụ : 1011
(3) Thực hiện phép chia modulo 2 giữa Dataword n bit với số
chia d3d2d1d0
(4) Phần dư của phép chia modulo 2 là số bit CRC
(5) Gắn số bit CRC vào bên phải Dataword: thu được Codewod
Bên gửi
97
98
Mô hình mã và giải mã CRC
• Bên nhận : Đưa Codeword vào bộ giải mã để tính
syndrome => Dựa trên giá trị của syndrome để phát
hiện có lỗi hay không
(1)Thực hiện phép chia modulo 2 giữa Codeword
nhận được với số chia d3d2d1d0 (vd : 1011)
=> thu được : Phần dư của phép chia modulo 2 là số
syndrome
(2)Xem xét giá trị của syndrome để phát hiện có lỗi
không : 2 trường hợp
Trường hợp 1 : Codeword nhận được là
codeword đúng
Bên nhận
99
Trường hợp 2 : Codeword nhận được là
codeword sai
100
Bên nhận
10
1
Tính mã CRC
◼ 1 0 0 1
• 1011 ) 1 0 1 0 0 0 0
◼ 1 0 1 1
◼ 0 0 1 0
◼ 0 0 0 0
◼ 0 1 0 0
◼ 0 0 0 0
◼ 1 0 0 0
◼ 1 0 1 1
◼ 0 1 1 (số dư )=> mã CRC cần tính
10
2
Test 1
• 1011 ) 1 0 1 0 0 1 1
1 0 1 1
0 0 1 0
0 0 0 0
0 1 0 1
0 0 0 0
1 0 1 1
1 0 1 1
0 0 0 => codeword không lỗi
10
3
Test 2
• 1011 ) 1 0 1 1 0 1 1
1 0 1 1
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 0
0 0 1 1
0 0 0 0
0 1 1 => codeword lỗi
10
4
CRC
• Bài tập : Tìm mã CRC với C(7,4) của dữ liệu
gửi là 1010, 1001, 1110
(Số chia dung trong bộ mã và giải mã là 1011)
10
5
CRC
• Bài tập : Kiểm tra mã codeword nhận được
sau là đúng hay sai.
• 1 0 1 1 0 1 0
• 1 0 1 0 0 1 1
• 1 0 0 1 0 0 1
• 0 0 1 1 0 1 0
Nếu đúng hãy tách lấy dataword
Mã sử dụng là mã CRC với C(7,4)
(Số chia dung trong bộ mã và giải mã là 1001)
Tổng kết
1. Hệ số đếm và các phép toán
2. Mã hóa tín hiệu số
3. Mã hóa và sửa lỗi

More Related Content

Similar to Chương 2_Official -E.pdf

Giáo trình kỹ thuật số chương 1-2.doc
Giáo trình kỹ thuật số chương 1-2.docGiáo trình kỹ thuật số chương 1-2.doc
Giáo trình kỹ thuật số chương 1-2.docMan_Ebook
 
Nmlt c16 ky_thuatlaptrinhdequy_in
Nmlt c16 ky_thuatlaptrinhdequy_inNmlt c16 ky_thuatlaptrinhdequy_in
Nmlt c16 ky_thuatlaptrinhdequy_inHuy Nguyễn
 
Nmlt c16 ky_thuatlaptrinhdequy
Nmlt c16 ky_thuatlaptrinhdequyNmlt c16 ky_thuatlaptrinhdequy
Nmlt c16 ky_thuatlaptrinhdequyMinh Ngoc Tran
 
Dethi hs gnamhoc20102011montoan
Dethi hs gnamhoc20102011montoanDethi hs gnamhoc20102011montoan
Dethi hs gnamhoc20102011montoanTam Vu Minh
 
CHƯƠNG I_Lop10 bai2_THÔNG TIN VÀ DỮ LIỆU
CHƯƠNG I_Lop10  bai2_THÔNG TIN VÀ DỮ LIỆUCHƯƠNG I_Lop10  bai2_THÔNG TIN VÀ DỮ LIỆU
CHƯƠNG I_Lop10 bai2_THÔNG TIN VÀ DỮ LIỆUSP Tin K34
 
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu SP Tin K34
 
Bai tap lon xac xuat thong ke
Bai tap lon xac xuat thong keBai tap lon xac xuat thong ke
Bai tap lon xac xuat thong keNgô Khắc Vũ
 
Giai nhanh phuong phap tinh
Giai nhanh phuong phap tinhGiai nhanh phuong phap tinh
Giai nhanh phuong phap tinhPham Huy
 
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongDe thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongLinh Nguyễn
 
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongDe thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongLinh Nguyễn
 
Ktmt kt c1_c2
Ktmt kt c1_c2Ktmt kt c1_c2
Ktmt kt c1_c2Ly hai
 
Toan d dh_2011
Toan d dh_2011Toan d dh_2011
Toan d dh_2011Huynh ICT
 
Toan pt.de049.2012
Toan pt.de049.2012Toan pt.de049.2012
Toan pt.de049.2012BẢO Hí
 
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐỗ Đức Hùng
 
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊN
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊNCHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊN
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊNBOIDUONGTOAN.COM
 

Similar to Chương 2_Official -E.pdf (20)

Gt kts
Gt kts Gt kts
Gt kts
 
Giáo trình kỹ thuật số chương 1-2.doc
Giáo trình kỹ thuật số chương 1-2.docGiáo trình kỹ thuật số chương 1-2.doc
Giáo trình kỹ thuật số chương 1-2.doc
 
Nmlt c16 ky_thuatlaptrinhdequy_in
Nmlt c16 ky_thuatlaptrinhdequy_inNmlt c16 ky_thuatlaptrinhdequy_in
Nmlt c16 ky_thuatlaptrinhdequy_in
 
Nmlt c16 ky_thuatlaptrinhdequy
Nmlt c16 ky_thuatlaptrinhdequyNmlt c16 ky_thuatlaptrinhdequy
Nmlt c16 ky_thuatlaptrinhdequy
 
Chuong1
Chuong1Chuong1
Chuong1
 
Ktmt chuong 2
Ktmt chuong 2Ktmt chuong 2
Ktmt chuong 2
 
01.toan
01.toan01.toan
01.toan
 
Dethi hs gnamhoc20102011montoan
Dethi hs gnamhoc20102011montoanDethi hs gnamhoc20102011montoan
Dethi hs gnamhoc20102011montoan
 
CHƯƠNG I_Lop10 bai2_THÔNG TIN VÀ DỮ LIỆU
CHƯƠNG I_Lop10  bai2_THÔNG TIN VÀ DỮ LIỆUCHƯƠNG I_Lop10  bai2_THÔNG TIN VÀ DỮ LIỆU
CHƯƠNG I_Lop10 bai2_THÔNG TIN VÀ DỮ LIỆU
 
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu
Lop10 _Chương1_ Bài 2 : Thông Tin Và Dữ Liệu
 
Bai tap lon xac xuat thong ke
Bai tap lon xac xuat thong keBai tap lon xac xuat thong ke
Bai tap lon xac xuat thong ke
 
Giai nhanh phuong phap tinh
Giai nhanh phuong phap tinhGiai nhanh phuong phap tinh
Giai nhanh phuong phap tinh
 
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongDe thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
 
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duongDe thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
De thi-dap-an-tuyen-sinh-vao-lop-10-mon-toan-tinh-hai-duong
 
Ktmt kt c1_c2
Ktmt kt c1_c2Ktmt kt c1_c2
Ktmt kt c1_c2
 
Toan d dh_2011
Toan d dh_2011Toan d dh_2011
Toan d dh_2011
 
Toan pt.de049.2012
Toan pt.de049.2012Toan pt.de049.2012
Toan pt.de049.2012
 
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
 
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊN
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊNCHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊN
CHUYÊN ĐỀ ĐẠI SỐ ÔN THI VÀO LỚP 10 CÁC TRƯỜNG CHUYÊN
 
Baitap 5637
Baitap 5637Baitap 5637
Baitap 5637
 

Chương 2_Official -E.pdf

  • 1. Digital Electronics Chapter 2: Number systems and codes
  • 2. Number systems Why do people think of decimal codes? Why do people think binary code? Why do people think of quadratic codes?
  • 3. 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 = (1.2) ◼ N = (251.41)10 = 2 x 102 + 5 x 101 + 1 x 100 + 4 x 10-1 + 1 x 10-2 a r i i i m n =− −  1
  • 4. 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
  • 5. Chapter 1 5 Number Systems (3) ◼ 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
  • 7. 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
  • 8. 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.
  • 9. Number Systems (4) ◼ Base Conversion Convert decimal to binary Convert binary to decimal
  • 10. Base Conversion (4) Examples ◼ (315)10 = (473)8 ◼ (315)10 = (13B)16 315 8 39 8 4 8 0 3 7 4 LSD MSD 315 16 19 16 1 16 0 B 3 1 LSD MSD
  • 11. Base Conversion (5) ◼ 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.
  • 12. 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 …
  • 13. Chapter 1 13 Base Conversion (6) ◼ 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)
  • 14. Base Conversion (6) ◼ Question: How to convert octal and hexadecimal to binary and vice versa?
  • 17. Arithmetic (1) ◼ Binary Arithmetic  Addition 111011 Carries 101011 Augend + 11001 Addend 1000100  Subtraction 0 1 10 0 10 Borrows 1 0 0 1 0 1 Minuend - 1 1 0 1 1 Subtrahend 1 0 1 0
  • 18. Arithmetic (2) ◼ Performs the following binary operations:: 1 1 0 1 1 + 1 0 1 0 Result? 1 0 0 0 1 0 0 - 1 0 1 0 1 1 Result? 1 0 0 1 0 0 - 1 1 0 1 1 Result?
  • 19. 19 Arithmetic (3) Multiplication 1 1 0 1 0 Multiplicand x 1 0 1 0 Multiplier 0 0 0 0 0 Partial products 1 1 0 1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 Product
  • 21. Arithmetic (5) Application of shift register in multiplication and division by 2
  • 23. Signed Number Representation ◼ Signed Magnitude Method  N = ± (an-1 ... a0.a-1 ... a-m)r is represented as N = (san-1 ... a0.a-1 ... a-m)rsm, where s = 0 if N is positive and s = r -1 otherwise.  N = -(15)10  In binary: N = -(15)10 = -(1111)2 = (1, 1111)2sm  In decimal: N = -(15)10 = (9, 15)10sm
  • 24. Complementary Number Systems (1) ◼ Complementary Number Systems  Radix complements (r's complements) [N]r = rn - (N)r where n is the number of digits in (N)r.  Diminished radix complements (r-1’s complements) [N]r-1 = rn - (N)r - 1
  • 25. Radix Complement Number Systems (2) ◼ Two's complement of (N)2 = (101001)2 [N]2 = 26 - (101001)2 = (1000000)2 - (101001)2 = (010111)2 ◼ (N)2 + [N]2 = (101001)2 + (010111)2 = (1000000)2 If we discard the carry, (N)2 + [N]2 = 0. Hence, [N]2 can be used to represent -(N)2. ◼ [ [N]2 ]2 = [(010111)2]2 = (1000000)2 - (010111)2 = (101001)2 = (N)2. ◼ Two's complement of (N)2 = (1010)2 for n = 6 [N]2 = (1000000)2 - (1010)2 = (110110)2. ◼ Ten's complement of (N)10 = (72092)10 [N]10 = (100000)10 - (72092)10 = (27908)10.
  • 26. Radix Complement Number Systems (3) ◼ Algorithm Find [N]r given (N)r .  First replace each digit, ak , of (N)r by (r - 1) - ak and then add 1 to the resultant. ◼ For binary numbers (r = 2), complement each digit and add 1 to the result. ◼ Example: Find 2’s complement of N = (01100101)2 . N = 01100101 10011010 Complement the bits +1 Add 1 [N]2 = (10011011)10 ◼ Example: Find 10’s complement of N = (40960)10 N = 40960 59039 Complement the bits +1 Add 1 [N]2 = (59040)10
  • 27. 27 Radix Complement Number Systems (4) ◼ Two's complement number system:  Positive number : ◼ N = +(an-2, ..., a0)2 = (0, an-2, ..., a0)2cns, where .  Negative number: ◼ N = (an-1, an-2, ..., a0)2 ◼ -N = [an-1, an-2, ..., a0]2 (two's complement of N), where .  Example: Two's complement number system representation of ± (N)2 when (N)2 = (1011001)2 for n = 8: ◼ +(N)2 = (0, 1011001)2cns ◼ -(N)2 = [+(N)2]2 = [0, 1011001]2 = (1, 0100111)2cns −   − − 1 2 1 N n 0 2 1 1   − − N n
  • 28. Radix Complement Number Systems (5) ◼ Example: Two's complement number system representation of -(18)10 , n = 8:  +(18)10 = (0, 0010010)2cns  -(18)10 = [0, 0010010]2 = (1, 1101110)2cns ◼ Example: Decimal representation of N = (1, 1101000)2cns  N = (1, 1101000)2cns = -[1, 1101000]2 = -(0, 0011000)2cns = -(24)2
  • 31. Fixed point number ± 0 1 1 0 0 1 0 0 1 Sign Integer bits Radix point Fixed point number: There is a fixed position separating the integer and fractional parts. Problem: can't decide how many bits for integer and fraction are appropriated Fractional bits
  • 32. Floating point number ± 0 1 1 1 0 0 1 1 1 E (Exponent) m (Mantissa) Sign bit
  • 33. Floating Point Numbers (1) ◼ N = M ´ rE, where  M (mantissa or significand) is a significant digits of N  E (exponent or characteristic) is an integer exponent. ◼ In general, N = ± (an-1 ... a0 .a-1 ... a-m)r is represented by  N = ± (.an-1 ... a-m)r ´ rn ◼ M is usually represented in sign magnitude:  M = (SM.an-1 ... a-m)rsm , where  (.an-1 ... a-m)r represents the magnitude  SM = (0: positive, 1: negative) ( ) (. ... ) −  − − 1 1 S n m r M a a
  • 34. Floating Point Numbers (1) Some common floating point number format
  • 35. Floating Point Numbers (1) Some common floating point number format
  • 37. Floating point number Số dấu chấm động có dạng: S E M B1: Chuyển đổi số trên ra hệ hai -2345,125 = -1001 0010 1001.001 B2: Chuẩn hoá theo IEEE 32bit -1001 0010 1001.001 => -1.001 0010 1001 001 x 2^11 B3: Xác định các thông số biểu diễn S,E,M S: phần định trị là số âm, nên S là 1 E : phần mũ được xác định là 8 bit E = 11+127=138=10001010 M: phần định trị được xác định là 001 0010 1001 0010 0000 0000 (23 bit) Dãy số là: S E M 1 10001010 00100101001001000000000 IEEE 32bit
  • 38. Biểu diễn số 23 trong hệ 10 theo chuẩn Chuẩn IEEE-754 32 bit (23)10 = (10111)2 = 1.0111e + 0100. • Sau dấu phẩy= 0111000 00000000 00000000. • Số mũ = 00000100. • Tính phần bù số mũ = 00000100 + 01111111 = 10000011. • Bit dấu là dương vì vậy nó sẽ là = 0. • (+23)10 = 01000001 10111000 00000000 00000000. • (–23)10= 11000001 10111000 00000000 00000000 Floating Point Numbers (1)
  • 39. Biểu diễn số -124 trong hệ 10 theo chuẩn Chuẩn IEEE-754 64 bit • Chuyển số (124)10 sang hệ nhị phân (124)10 = (10001110)2. • (10001110)2 = 1.000 1110 × 27 = 1.0001110e + 0111. • Số mũ = 00000000111. • Phần bù của số mũ = 00000000111 + 01111111111 = 00010000110. • Sau dấu phẩy = 0001110 00000000 00000000. • Dấu của số số = 1. • Vì vậy, (-124)10 = 11000011 00001110 00000000 00000000.
  • 40. Xác định số thập phân tương đương cho các số dấu phẩy động sau: 00111111 01000000 00000000 00000000 (chuẩn IEEE-754 32 bit); 00111111 01000000 00000000 00000000 (chuẩn IEEE-754 32 bit); Bit đầu tiên của số là 0 => số dương Phần bù của số mũ là: 0111111 0 Tách phần số mũ = 0111111 0 – 01111111 = 11111111 (số âm) Vì 0111111 0 < 01111111 Chuyển phần số mũ sang số dương: 00000001 => phần mũ của số là – 00000001 Phần sau dấu phẩy: 1000000 00000000 00000000 => 1.1000000 00000000 00000000 Vì số mũ của số là -00000001=-1 => Phần sau dấu phẩy là: 1.1000000 00000000 00000000 => 0.11000000 00000000 00000000 Số cần tìm là: (0.11)2=(0.75)10
  • 41. Xác định số thập phân tương đương cho các số dấu phẩy động sau: 11000000 00101001 01100 … 45 số 0 (theo chuẩn IEEE-754 64 bit). 11000000 00101001 01100 … 45 số 0 (theo chuẩn IEEE-754 64 bit). Bit đầu tiên của số là 1 => số âm Phần bù của số mũ là: 1000000 0010 Tách phần số mũ = 1000000 0010 – 01111111111 = 00000000011 = (3)10 Phần sau dấu phẩy: 1001 01100 … 45 số 0 => 1.100101 01100 … 45 số 0 Vì số mũ của số là 3 => Phần sau dấu phẩy là: 1.100101 01100 … => 1100.101 01100 Số cần tìm là: (- 1100.101 011)2=(-12.625)10
  • 42. Problems: Represent the following in the IEEE-754 floating-point standard using the single-precision format: 1. (−118.625)10 2. (118.015)10 3. (−412.623)10 4. (512.128)10 Convert following floating-point standard single-precision binary to decimal number 1. 11110000 11001100 10101010 00001111 2. 01110011 11101100 10101010 00000000 3. 10110000 11001100 11111110 00001100 4. 01111110 11001100 10101011 00000000
  • 43. Coding Assume that you want to communicate with your friend with a flashlight in a night, what will you do? What is the problem? Drawing the word?
  • 44. Coding Solution #1 •A: 1 blink •B: 2 blinks •C: 3 blinks : •Z: 26 blinks What’s the problem? •How are you? = 131 blinks
  • 45. Coding Solution #2 - Morse code Hello
  • 46. Lookup •It is easy to translate into Morse code than reverse. Why?
  • 47. Tra mã hóa (Lookup) Số của mã = 2số chấm và số gạch Tại sao lại phải dùng . và -?
  • 48. Tra mã hóa (Lookup) Useful for checking the correctness/ redundency
  • 49. Mã hóa (Lookup) – Braille Louis Braille Braille code
  • 50. Tra mã hóa (Lookup) Braille
  • 51. Tra mã hóa (Lookup) Braille Morse Both of these encodings are binary
  • 52. Binary representations •Electronic Implementation –Easy to store with bistable elements –Reliably transmitted on noisy and inaccurate wires 0 0 3.3V 2.8V 0.5V 0.0V 1
  • 53. Why encryption? Today's digital computers only understand the numbers 0 and 1, so any information in the form of digits, letters, characters ... must be converted to binary form
  • 54. Coding areas Coding areas include: - Decimal encoding - Character encoding - Script encoding - Voice coding - Image encoding - …
  • 55. BCD – Binary coded 4 bits are required to encode decimal numbers Bitcoin Code Diamond
  • 56. BCD – Binary coded decimal • Weighted BCD code • Non-weighted BCD code (excess-3, gray, ASCII) Category:
  • 57. BCD – Binary coded decimal • A weighted BCD code is one that allows analysis into polynomials according to its weight. • Weighted BCD codes are divided into two types of codes: - Natural BCD Code: A code in which the weights are usually arranged in ascending order Example: BCD 8421, BCD 5421 - Arithmetic BCD code; A code that is symmetric through a middle path Example : BCD 2421, BCD 5121, BCD8 4-2-1
  • 58. BCD – Binary coded decimal ◼ BCD is used to represent information such as strings of letters or numbers ◼ Each position has a weight ◼ BCD Codes: 0: 0000 1: 0001 2: 0010 3: 0011 4: 0100 5: 0101 6: 0110 7: 0111 8: 1000 9: 1001  Example: (9750)10 = (1001 0111 0101 0000)BCD
  • 59. BCD – Binary coded decimal
  • 60. BCD – Binary coded decimal Đối xứng nhau Arithmetic BCD code
  • 61. BCD – Binary coded decimal
  • 62. BCD – Binary coded decimal
  • 63. BCD – Binary coded decimal BCD 8421 code recognition circuit: There will be no number where a3 and a1 or a3 and a2 are equal to 1 y = 1 Not BCD y = 0 BCD
  • 64. BCD – Binary coded decimal Mạch nhận dang mã BCD 8421: There will be no number where a3 and a1 or a3 and a2 are equal to 1 y = Not BCD y = 0 BCD
  • 66. Các phép tính trên số BCD Do số BDC chỉ có giá trị từ 0->9 nên đối với những số thập phân lớn hơn sẽ chia số thập phân thành các phần, mỗi phần được biểu diễn bởi 1 số BCD tương ứng:
  • 67. Các phép tính trên số BCD Phép trừ tính trên số BCD theo quy tắc sau: A – B = A + B’ trong đó B’ là phần bù của B
  • 68. BCD advantages and disadvantages
  • 69. ASCII ◼ ASCII (American Standard Code for Information Interchange) Character sets Standard ASCII(0 – 127) Extended ASCII (0 – 255) ◼ – ANSI (0 – 255) ◼ – Unicode (0 – 65,535) Character BCD Decimal D 1000100 44 i 1101001 69 g 1100111 67 i 1101001 69 t 1110100 74 a 1100001 61 l 1101100 6C
  • 70. ASCII
  • 71. Assignment Bài tập 1: Chuyển đổi các số thập phân sau sang hệ nhị phân, bat phân và thập lục phân: 9210, 14410, 40910, 25410, 25610, 6452210 Bài tập 2: Chuyển đổi các số sau sang số bù nhị phân 8 bit: -110, -510, -1710, -6410, -12810, 2510. Bài tập 3: Thực hiện phép tính số học sau bằng phương pháp trừ nhị phân và sử dụng số bù 2: 6110 - 1710 = ? Bài tập 4: Biểu diễn các số thập phân sau bằng mã nhị phân vầ mã BCD(2421): 1610 và 199910
  • 72. Error Detection and Correction code 7 2 Error detection/correction code: Information is encoded in such a way that a particular class of errors can be detected and/or corrected.
  • 73. Contents • Concept • Hamming code • CRC check
  • 74. Concepts ◼ An error: An incorrect value in one or more bits. ◼ Single error: An incorrect value in only one bit. ◼ Multiple error: One or more bits are incorrect. ◼ Errors are introduced by hardware failures, external interference (noise), or other unwanted events.
  • 75. Concepts • Error detection rule: If only transmitting the correct data to be transmitted, the error cannot be detected Need to send more information with the data  Information attached to help detect errors • Method: Mã khối – Block coding Split the data into k-bit blocks and convert to n-bit blocks, where n = k +r => Error detection and correction is done at the Data link layer
  • 76. 76 Concepts • Example: Vertical Redundancy Check (VRC) technique Add a bit to the end of the data block, according to the rule: "Total number of 1's is even“ The extra bit is called Parity Check. Example: check even 0110011 → 01100110 0110001 → 01100011 Comment: Only odd number of errors detected // bit thêm vào là 0 để tổng số bit 1 là chẵn // bit thêm vào là 1 để tổng số bit 1 là chẵn
  • 78. Model 0110011 01100110 00100110 Thêm bit kiểm tra Check number of 1s Lỗi Data word Code word Example: 78 Add check bit
  • 79. 79 Method – Error detection • To detect errors: - The receiver has a list of correct code words - If the received code word is not in the list -> there is an error => Comment: only detect errors according to the preset design
  • 80. Example: Word code table for error detection • Code word (code word) has an even number of 1’s • Codewords do not overlap, differ by 2 bits 80
  • 81. Hamming distance • Khoảng cách Hamming giữa 2 từ cùng độ dài : là số bit (ở cùng vị trí ) khác nhau • Khoảng cách Hamming tối thiểu : là khoảng cách nhỏ nhất giữa 2 cặp bất kỳ có trong một tập từ. Ví du: d(000, 011) là 2 Vì 81
  • 82. Khoảng cách Hamming dmin trong bảng sau là 2 82
  • 83. 83 Khoảng cách Hamming • Định lý 1 : Để đảm bảo phát hiện lỗi của s bit thì khoảng cách Hamming cực tiểu trong các cặp từ mã phải là dmin = s+1 • Định lý 2: để sửa t lỗi , khoảng cách Hamming cực tiểu trong các từ mã phải là dmin = 2t +1
  • 84. 84 Mã Hamming • Dùng để sửa lỗi • Mã Hamming xem xét trong bài này có dmin = 3 => Theo định lý 2: dùng để sửa 1 lỗi
  • 85. Cấu trúc của bộ mã hóa và bộ giải mã Hamming C(7,4) 85
  • 86. Cho bảng mã Hamming C(7,4) 86 Mã Hamming
  • 87. 87 r0=a2+a1+a0 module2 r1=a3+a2+a1 module2 r2=a0+a1+a3 module2 Ký hiệu : Data word : a3 a2 a1 a0 1010 Code word : a3 a2 a1 a0 r2 r1 r0 1010001 Xác định code word <=> tính r2 r1 r0 Mã Hamming
  • 88. Chuỗi bit nhận được cần kiểm tra : b3b2b1b0q2q1q0 (1)Tính syndrome: s2s1s0 (2)nếu s2s1s0 = 000 thì không có lỗi ngược lại: =>có lỗi s0=b2+b1+b0+q0 module 2 = 1 % 2 = 1 s1=b3+b2+b1+q1 module 2 = 1 %2 = 1 s2=b0+b1+b3+q2 module 2 =(0+0+1+0)%2 =1 88 Giải Mã Hamming
  • 89. Logical decision made by the correction logic analyzer Cách sửa lỗi : (1)tìm bit bị lỗi dựa vào bảng dò lỗi sau (2)đảo ngược bit lỗi 89 Sửa Lỗi Mã Hamming
  • 90. 90 Mã Hamming •VD1 : Bên nhận nhận được code word 0100011 Xác định dataword? Giải : 0100011: b0 = 0/ b1 = 0/ b2 =1/ b3 =0/ q0=1/ q1=1/q2=0 s0=b2+b1+b0+q0 s0=1+0+0+1 = 10 module 2 = 0 s1=b3+b2+b1+q1 s1= 0+1+0+1 = 10 module 2 = 0 s2=b0+b1+b3+q2 s2=0+0+0+0 = 0 module 2 = (0+0+0+0)%2=0 Tính syndrome s2s1s0= 000 Kết luận : Code word nhận được không lỗi Data word là 4 bit cực trái: 0100
  • 91. Mã Hamming •VD2 : Bên nhận nhận được code word 0101011 Xác định data word ? Giải : Tính syndrome s2s1s0 = 101 (ghi chi tiết cách tính s2, s1, s0 … ) Kết luận : code word nhận được bị lỗi Dựa theo bảng : bit lỗi là b0 Sửa bit b0 => Data word là 4 bit cực trái : 0100
  • 92. Mã Hamming Bài tập: Xác định lỗi nếu có và sửa lỗi dựa trên tín hiệu nhận được sử dụng mã Hamming Codeword: 0101010, 1111011, 0111011
  • 93. 93 Mã phát hiện lỗi Cyclic Redundancy Check (CRC) • CRC là một phương pháp để phát hiện lỗi bằng cách gắn thêm một khối bit phía sau khối dữ liệu • Các bit bổ sung thêm vào gọi là các bit CRC • Có một số phương pháp cài đặt : modulo 2, đa thức, …
  • 94. Mô hình mã và giải mã CRC 94
  • 95. 95 Mô hình mã và giải mã CRC • Bên gửi : – Đầu vào : Dataword 4 bit – Dùng bộ mã để tính r2r1r0 • Bên nhận : – Nhận Codeword 7 bit => thu được Codeword 7 bit – Dùng bộ giải mã để tính Syndrome • Nếu Syndrome ≠ 0 => một hoặc nhiều bit bị lỗi • Nếu Syndrome = 0 : 2 trường hợp – Không có lỗi => Thu được Dataword – Một số bit bị lỗi , nhưng bộ giải mã không phát hiện được
  • 96. 96 Mô hình mã và giải mã CRC • Bên gửi : thực hiện mã Dataword k bits (k= 4) => kết quả thu được Codeword n bits (n= 7) => truyền Codeword đi. Quy trình mã hóa với Dataword k =4bit, Codeword n =7: (1)Thêm vào bên phải Dataword số bit 0 là n-k (3 bit) (2)Một số chia xác định trước d3d2d1d0, có số bit n-k+1 Ví dụ : 1011 (3) Thực hiện phép chia modulo 2 giữa Dataword n bit với số chia d3d2d1d0 (4) Phần dư của phép chia modulo 2 là số bit CRC (5) Gắn số bit CRC vào bên phải Dataword: thu được Codewod
  • 98. 98 Mô hình mã và giải mã CRC • Bên nhận : Đưa Codeword vào bộ giải mã để tính syndrome => Dựa trên giá trị của syndrome để phát hiện có lỗi hay không (1)Thực hiện phép chia modulo 2 giữa Codeword nhận được với số chia d3d2d1d0 (vd : 1011) => thu được : Phần dư của phép chia modulo 2 là số syndrome (2)Xem xét giá trị của syndrome để phát hiện có lỗi không : 2 trường hợp
  • 99. Trường hợp 1 : Codeword nhận được là codeword đúng Bên nhận 99
  • 100. Trường hợp 2 : Codeword nhận được là codeword sai 100 Bên nhận
  • 101. 10 1 Tính mã CRC ◼ 1 0 0 1 • 1011 ) 1 0 1 0 0 0 0 ◼ 1 0 1 1 ◼ 0 0 1 0 ◼ 0 0 0 0 ◼ 0 1 0 0 ◼ 0 0 0 0 ◼ 1 0 0 0 ◼ 1 0 1 1 ◼ 0 1 1 (số dư )=> mã CRC cần tính
  • 102. 10 2 Test 1 • 1011 ) 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 1 0 0 0 => codeword không lỗi
  • 103. 10 3 Test 2 • 1011 ) 1 0 1 1 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 => codeword lỗi
  • 104. 10 4 CRC • Bài tập : Tìm mã CRC với C(7,4) của dữ liệu gửi là 1010, 1001, 1110 (Số chia dung trong bộ mã và giải mã là 1011)
  • 105. 10 5 CRC • Bài tập : Kiểm tra mã codeword nhận được sau là đúng hay sai. • 1 0 1 1 0 1 0 • 1 0 1 0 0 1 1 • 1 0 0 1 0 0 1 • 0 0 1 1 0 1 0 Nếu đúng hãy tách lấy dataword Mã sử dụng là mã CRC với C(7,4) (Số chia dung trong bộ mã và giải mã là 1001)
  • 106. Tổng kết 1. Hệ số đếm và các phép toán 2. Mã hóa tín hiệu số 3. Mã hóa và sửa lỗi