Professional Documents
Culture Documents
Why do people
think of
quadratic
codes?
◼ 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
5 Chapter 1
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.
Examples:
◼ (11010)2 →( ? )10
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
◼ (315)10 = (13B)16
16 315 B LSD
16 19 3
16 1 1 MSD
0
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 )
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
◼ (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
…
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)
13 Chapter 1
Base Conversion (6)
◼ Question: How to convert octal
and hexadecimal to binary and
vice versa?
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::
11 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?
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
17
Arithmetic (4)
Division
Dividend Divider
Quotient
Remainder
Arithmetic (5)
where − 1 N −2 n −1.
24 Chapter 1
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
± 0 1 1 0 0 1 0 0 1
± 0 1 1 1 0 0 1 1 1
Sign E m
bit (Mantissa)
(Exponent)
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.
Dãy số là:
SE M
1 10001010 00100101001001000000000
Coding
Assume that you want to communicate with
your friend with a flashlight in a night, what
will you do?
Hello
Lookup
Useful for
checking the
correctness/
redundency
Mã hóa (Lookup) – Braille
Braille
Tra mã hóa (Lookup)
Morse Braille
Both of these
encodings are binary
Binary representations
•Electronic Implementation
–Easy to store with bistable elements
–Reliably transmitted on noisy and inaccurate wires
0 1 0
3.3V
2.8V
0.5V
0.0V
Why encryption?
4 bits are
required to
encode decimal
numbers
BCD – Binary coded decimal
Category:
• Weighted BCD code
• Non-weighted BCD code
(excess-3, gray, ASCII)
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
y = 1 Not BCD
y = 0 BCD
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
Error detection/correction code: Information is encoded in such a
way that a particular class of errors can be detected and/or corrected.
5
8
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
63
Model
Example:
Data word
0110011 Lỗi
01100110 00100110
Code word
64
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
65
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
66
Hamming distance
67
Khoảng cách Hamming
dmin trong bảng sau là 2
68
Khoảng cách Hamming
69
Mã Hamming
70
Cấu trúc của bộ mã hóa và bộ giải mã Hamming C(7,4)
71
Mã Hamming
Cho bảng mã Hamming C(7,4)
72
Mã Hamming
Ký hiệu :
Data word : a3 a2 a1 a0 1010
Code word : a3 a2 a1 a0 r2 r1 r0 1010001
73
Giải 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
74
Sửa Lỗi Mã Hamming
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
75
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
Giải :
Tính syndrome s2s1s0 = 101
(ghi chi tiết cách tính s2, s1, s0 … )
79
Mô hình mã và giải mã CRC
80
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
=> thu được Codeword 7 bit
• Bên nhận :
– Nhận Codeword 7 bit
81
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.
82
Bên gửi
83
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
84
Trường hợp 1 : Codeword nhận được là
codeword đúng
Bên nhận
85
Trường hợp 2 : Codeword nhận được là
codeword sai
Bên nhận
86
Tính mã CRC
◼ 1001
• 1011 ) 1 0 1 0 0 0 0
◼ 1011
◼ 0010
◼ 0000
◼ 0100
◼ 0000
◼ 1000
◼ 1011
◼ 0 1 1 (số dư )=> mã CRC cần tính
87
Test 1
• 1011 ) 1 0 1 0 0 1 1
1011
0010
0000
0101
0000
1011
1011
0 0 0 => codeword không lỗi
19/09/2016 88
Test 2
• 1011 ) 1 0 1 1 0 1 1
1011
0000
0000
0001
0000
0011
0000
0 1 1 => codeword lỗi
89
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)
19/09/2016 90
CRC
• Bài tập : Kiểm tra mã codeword nhận được
sau là đúng hay sai.
• 1011010
• 1010011
• 1001001
• 0011010
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)
19/09/2016 91
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