Lectures 5 and 6

Download Report

Transcript Lectures 5 and 6

CS 3510 - Chapter 2 (3 of 5)
Dr. Clincy
Professor of CS
Introduce Lab Instructor:
Mr. Varahala Raju Dendukuri, J-265,
[email protected]
Dr. Clincy
Lecture 3
Slide 1
Recap Signed Numbers
• Sign-Magnitude
• 1’s Complement
• 2’s Complement
Dr. Clincy
Lecture 9 and 10
2
Multiplication in base 2 – dealing with negative numbers
• By hand – signed case – best to use 2’s complement
• If both numbers are negative, perform as if both numbers are positive
• If one is negative and one number is positive, see below – extend out
left-most bit
Dr. Clincy
Lecture
Lecture
9 and 10
3
How does the computer multiply (shifting) ?
• Computer doesn’t actually multiply – it adds and shifts
Will cover Booth’s Algorithm in a later lecture
Dr. Clincy
Lecture
Lecture
9 and 10
4
Character Codes
• Calculations aren’t useful until their results can
be displayed in a manner that is meaningful to
people.
• We also need to store the results of calculations,
and provide a means for data input.
• Thus, human-understandable characters must be
converted to computer-understandable bit
patterns using some sort of character encoding
scheme.
Dr. Clincy
Lecture 9 and 10
5
Character Codes
• Binary-coded decimal (BCD) was one of these
early codes. It was used by IBM mainframes in the
1950s and 1960s.
• In 1964, BCD was extended to an 8-bit code,
Extended Binary-Coded Decimal Interchange
Code (EBCDIC).
• Until recently, ASCII was the dominant character
code outside the IBM mainframe world.
• Many of today’s systems embrace Unicode, a 16bit system that can encode the characters of every
language in the world
Dr. Clincy
Lecture 9 and 10
6
ASCII
Dr. Clincy
Dr. Clincy
- CS2350
Lecture 9 and 10
77
EBCDIC
Lecture
Dr.
Clincy
9 and 10
8
Error Detection Vs Error Correction
• Error Detection – determining if an error occurred or
not
• Error Correction – given an error has occurred,
correcting the error – much more complex than error
detection
– (Method 1) Fix the error by retransmitting the frame that is in
error - Rx ask the Tx to retransmit
– (Method 2) Forward error control – fixing the error on the Rx
side (complex)
Dr. Clincy
Lecture 9 and 10
9
Error Control Techniques
Trade off between detection probability and
processing requirements
Approaches
Detection
• Simple Parity (Double Parity)
• Cyclic Redundancy Checksum
Error correction
• Hamming Approach
Dr. Clincy
Lecture 9 and 10
10
Error Detection: Single Parity
• Bit added to each character to make all bits add up to an even
number (even parity) or odd number (odd parity)
• Good for detecting single-bit errors only
• High overhead (one extra bit per 7-bit character=12.5%)
Examples of parity bits
•What’s the disadvantage ?: what happens for 2 bit
errors ?
.
Dr. Clincy
Lecture
Lecture
9 and 10
11
Do Some Examples w/students
•Even, 110101
•Odd, 110110
•Odd, 1010101
•Even, 11111
Dr. Clincy
Lecture
Lecture
9 and 10
12
Parity Bit Concept
•
•
•
•
•
Given the word: 1011011 – add “parity bit”
Even Parity: even # of 1’s: 11011011
Odd Parity: odd # of 1’s: 01011011
What’s the disadvantage ?: what happens for 2 bit errors ?
Another Example:
•
•
Encode 1100 in (a), even parity added in (b), Error in AC in (c)
NOW, do we see how we can use the Parity Bit Concept to Detect Errors
Dr. Clincy
Lecture
13
Error Detection: Double Parity
•
•
•
•
•
Uses horizontal and longitudinal parity
Individual characters are grouped together in a block
Each row (character) would have a parity bit
Each column would have a parity bit
The group of parity bits formed by the rows and columns
1101011 1
1111111 1
0101010 1
0011001 1
Parity
bits (B)
If 1 bit is in error,
(B) catches it, if 2
bits are in error, (A)
catches it
0100111 0
Parity
bits (A)
Dr. Clincy
Lecture
14
Do some examples w/students
Even
• 111101
• 101010
• 110011
Even
• 110001
• 100010
• 110011
Odd
• 10001
• 11010
• 11100
Odd
• 11101
• 11010
• 11000
Dr. Clincy
Lecture
15
CS 3501 - Chapter 2 (4 of 5)
Dr. Clincy
Professor of CS
- First Exam - Tuesday, June 14th at 11am
- Good News: Only cover Ch 2 (not Ch 1)
- Format: Closed Book, No Laptop, No Phone, Can
use calculator
- Format: Short Problems, Problems – must show
correct work to get credit
-Dr. Clincy
2 hour lab afterwards Lecture 3
Slide 16
Error Control Techniques
Trade off between detection probability and
processing requirements
Approaches
Detection
• Simple Parity (Double Parity) – already covered
• Cyclic Redundancy Checksum
Error correction
• Hamming Approach
Dr. Clincy
Lecture 9 and 10
17
Conceptually, How does CRC works ?
On the Tx side
1. An agreed-to divisor is used by both the Tx and Rx
2. The dataword is augmented (zeros added) based on the size of
the divisor (setting up the dataword to be divided)
3. The “augmented dataword” is divided by the divisor
4. The quotient is discarded and the remainder is subtracted from
the divisor to get the data that needs to be appended to the
“augmented dataword”
5. Append the results in 4 to the “augmented dataword”
6. The result in 5 is sent to the receiver
On the Rx side
1. The augmented dataword with “divisor subtract remainder”
appended is received
2. The Rx uses the same divisor as the Tx and divides the data in 1
3. If no errors occurred, the remainder will be zero
Dr. Clincy
18
Conceptually, How does CRC works ?
Example using decimal numbers
Data needing to be sent is 546 and let the common divisor be 8
On the Tx side
1.
2.
3.
4.
5.
Shift 546 to the left (adding the appropriate amount of zeros) - 5460
Divide 5460 by 8 – get quotient 682 and remainder 4
Subtract remainder 4 from divisor 8 – get 4
Append or add the results in step 3 to 5460 - 5464
Send 5464 to the receiver
On the Rx side
1.
2.
3.
Divide 5464 by the same divisor – 5464/8
Quotient equals 683 and the remainder equals 0
No errors occurred because the remainder is zero
Dr. Clincy
19
CRC using regular binary division
Appropriate # of
zeros added to
dividend 1001
Determine
remainder
Subtract
remainder
from divisor
to determine
what to
append
Append
result to
dividend
Dr. Clincy
Rx
performs
the same
calculation
using the
new
dividend
and gets a
remainder
of zero
20
Recall that “Black Boxes” do not subtract.
In making the CRC approach less
complex, Modulo-2 division is used
Modulo-2 division uses XOR versus
regular subtraction
The remainder result from Modulo-2
division is the final product (no need to
subtract it from the divisor) – the Tx
simply adds it to the augmented
dataword
Dr. Clincy
21
Introducing Modulo-2 Arithmetic
Modulo-2 is used for error detection and correction
Modulo-2 has no carry over for addition and subtraction
Use the exclusive OR (XOR) for modulo-2
XORing of two single bits or two words
0 if two bits are the same
1 if two bits are different
Dr. Clincy
22
Division for CRC using Modulo-2
Looking at
the # of bits
to divide
Tx
Rx
1 0 1 0
10 1 0
Module-2
arithmetic
here
Dr. Clincy
23
CRC using Modulo-2 Division
More
Examples
Dr. Clincy
24
Cyclic Code Representation
Typically, a frame or packet of
data is represented as a
mathematical polynomial
Dr. Clincy
25
Error Detection: Cyclic Redundancy Check
• Treat the frame or packet of data/bits as a mathematical
polynomial
• Right-most bit corresponds to x0
• Next bit corresponds to x1
• …Etc…
• nth bit corresponds to xn
• If the bit is 1, include x(i) in the polynomial
• If the bit is 0, do not include x(i) in the polynomial
• For example, 101001101 would correspond to:
• x8 + x6 + x3 + x2 + x0
•
The Tx would take this polynomial and divide it by a given generated polynomial
Dr. Clincy
26
CRC Approach using polynomials
Example
• Using the generator polynomial of x5 + x4 + x2 + 1, send
the message 1010011010
• 1st: append some zeros to the end of the message you are
sending. The number of zeros to append will depend on the
degree of the polynomial (i.e. x4 + x3 +x0 has a degree of 4)
• In our example, we have a degree of 5 – so add five 0’s
• 101001101000000
• 2nd: x5+x4+x2+1 translate to bit stream 110101
• 3rd: Divide 101001101000000 by 110101 using modulo-2
• 4th: Append remainder to original message and send to Rx
Dr. Clincy
27
Understanding Hamming
Distance Concept
Dr. Clincy
28
Error Correction –
Hamming Code Concept
• Computers make errors occasionally due to voltage spikes and etc.
• Recall Encoding Concept – codes representing characters
• Hamming Distance of 1: change in 1 bit creates a new code
D001
What happens
with 1 bit in
error ?
C011
A000
B010
H101
G111
E100
Dr. Clincy
F110
29
Hamming Distance of 2
001
What happens
with 1 bit in
error ?
A000
010
What happens
with 2 bits in
error ?
D101
111
100
Dr. Clincy
B011
C110
30
Hamming Distance of 3
001
What happens
with 1 bit in
error ?
What happens
with 2 bits in
error ?
011
A000
010
101
B111
What happens
with 3 bits in
error ?
100
Dr. Clincy
110
31
Hamming Error Correcting
Approach
• 1st: Determine the number of parity bits to
add to the code word for checking
• 2nd: determine bit positions of each added
parity bits
• 3rd: Determine what each parity bit checks
Dr. Clincy
32
Hamming Code Example
(Understand the “how” vs “why”)
•
•
•
•
•
•
•
•
•
•
Example: Given a 4-bit code and even parity request – recall parity
Determine number of parity bits to add: 20=1, 21=2, 22=4: also determine
bit positions of parity bits – 1, 2 and 4 (with labels C1, C2 and C4)
Let the 4-bit code have labels I3, I5, I6 and I7 due to the parity bit positions
Therefore the seven bits would be transmitted in the following order: C1 C2
I3 C4 I5 I6 I7
Determine what each parity bit checks: add the parity positions to
determine this (must be less than or equal to 7 in this case): C1 case: 1+2=3,
1+4=5, 1+2+4=7; C2 case: 2+1=3, 2+1+4=7, 2+4=6; C4 case: 4+1=5,
4+2=6, 4+2+1=7
For example, transmitting the 4-bit code of 0101 (I3I5I6I7) would be
0100101 (red bits are parity bits)
If I3 was corrupted during transmission, C1 and C2 would detect it (1+2=3)
If I5 was corrupted during transmission, C1 and C4 would detect it (1+4=5)
If I6 was corrupted during transmission, C2 and C4 would detect it (2+4=6)
If I7 was corrupted during transmission, C1 , C2 and C4 would detect it
(1+2+4=7)
Dr. Clincy
33