This preview shows page 1. Sign up to view the full content.
Unformatted text preview: CSE261 Spring 2008 Positional Number System Number Systems And Codes
Positional Positional Binary General form of a number:
Most significant digit (MSB) Least significant digit (LSB) number systems number system conversions dp1dp2...d0.d1d2..dn Radix Point The value of the number: system operations techniques
CSE261 C2 #1 #1 Encoding D = i =  n p  1 d i r i Radix or Base
CSE261 C2 #2 #2 Decimal System
d:0,1,2,...,9
p=4,n=2 Binary System
b:0,1
p=4,n=2 r = 10 r=2 1453.05
d 2 5x102 d 1 d1 5x101 d0 0x101 3x100 1101.01
b 2 1x22 d3 1x103 d2 4x102 b3 1x23 b2 1x22 b 1 b1 0x21 b0 1x20 0x21 1x103 + 4x102 + 5x101 + 3x100 + 0x101 + 5x102 = 1453.05
CSE261 C2 #3 #3 1x23 + 1x22 + 0x21 + 1x20 + 0x21 + 1x22 = 13.25
CSE261 C2 #4 #4 Numerical Systems and Codes 1 CSE261 Spring 2008 Exercise
Calculate the equivalent decimal numbers:
12 102 112 1002 1x20 = 1 1x2 1x21 + 0x20 = 2 + 0 = 2 1x2 0x2 1x21 + 1x20 = 2 + 1 = 3 1x2 1x2 1x22 + 0x21 + 0x20 = 4 + 0 + 0 = 4 0x2 0x2 1x2 Octal and Hexadecimal Numbers
Octal number System: r=8 d : 0, 1, 2, ... , 7 Hexadecimal number System: r = 16 d : 0, 1, 2, ..., 9, A, B, C, D, E, F
Used for representations of long binary numbers 10112 1x23 + 0x22 + 1x21 + 1x20 = 8 + 0 + 2 + 1 = 11 0x2 1x2 1x2 1x2
CSE261 C2 #5 #5 CSE261 C2 #6 #6 Binary,Decimal,Octal and Hexadecimal Numbers
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Octal 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
CSE261 C2 #7 #7 Binary Octal Conversion
Starting from the decimal point: Separate the bits into groups of three Replace each group with its corresponding Octal digit 100011110 . 101012 = 100011110 10101 100 011 110 . 101 0102 = 436 . 528 CSE261 C2 #8 #8 Numerical Systems and Codes 2 CSE261 Spring 2008 Binary  Hexadecimal Conversion
Starting from the decimal point: Separate the bits into groups of four Replace each group with its corresponding Hexadecimal digit Octal  Binary Conversion
Convert each Octal digit into its corresponding 3 bit string 100011110 . 101012 = 00011110 10101 0001 0001 1110 . 1010 10002 = 11E . A816 436 . 528 = 100 011 110 . 101 0102 CSE261 C2 #9 #9 CSE261 C2 #10 #10 Hexadecimal  Binary Conversion
Convert each Hexadecimal digit into its corresponding 4 bit string radixr to decimal Conversion radix A5E . C816 1010 0101 1110 . 1100 10002 D = i =  n p  1 d i r i CSE261 C2 #11 #11 CSE261 C2 #12 #12 Numerical Systems and Codes 3 CSE261 Spring 2008 Decimal to radixr Conversion radix4510 Decimal to Binary Conversion
45/2 = 22 The remainder is 1 0 The remainder is 1 1 0 1 LSB 16 0 8 1 4 1 2 0 1 1
CSE261 C2 #14 #14 LSB Successive The division of D by r 22/2 = 11 11/2 = 5 remainder of the long division will give the digits starting from the least significant digit 5/2 = 2 2/2 = 1 1/2 = 0 MSB 32
CSE261 C2 #13 #13 MSB 1 Exercise
Convert 5 into binary: hexadecimal: Convert 17 into binary: hexadecimal: Convert 34 into binary: hexadecimal: 101 5 10001 11 100010 22
CSE261 C2 #15 #15 Binary Addition
Binary addition table: carry in 0 0 0 0 1 1 1 1 X 0 0 1 1 0 0 1 1 Y 0 1 0 1 0 1 0 1 X+Y carry out 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 CSE261 C2 #16 #16 Numerical Systems and Codes 4 CSE261 Spring 2008 Example:
16 8 4 2 1 1 0 1 0 1 0 1 1 0 0 1 0 0 0 0 1 21 12 33 Exercise:
16 8 4 2 1 1 1 0 0 1 + 0 1 0 0 1 1 0 0 0 1 0 25 9 34 CSE261 C2 #17 #17 CSE261 C2 #18 #18 Binary Subtraction
Binary Subtraction table: borrow in 0 0 0 0 1 1 1 1 X 0 0 1 1 0 0 1 1 Y 0 1 0 1 0 1 0 1 XY 0 1 1 0 1 0 1 1 borrow out 0 1 0 0 1 1 0 1 Example:
16 8 4 2 1 1 1 0 1 0 0 1 1 1 1 0 1 0 1 1 26 15 11 CSE261 C2 #19 #19 CSE261 C2 #20 #20 Numerical Systems and Codes 5 CSE261 Spring 2008 Representation of Negative Numbers in Binary Systems Signed Magnitude Representation
The MSB represents the sign bit (0 = positive, 1 = negative) Signedmagnitude Representation. SignedTwo'sComplement Representation. Two' One'sComplement Representation. One' The range for nbit is: n from 2n1 1 to +2n1 1. Example: n=5, Range: from 15 to 15 10011 = 3 , 01100 = +12 01100 00000 = 0 , 10000 = 0 10000
Disadvantages:
1. 2. Complicated digital adders Two possible representations of zero
CSE261 C2 #22 #22 CSE261 C2 #21 #21 Two's Complement Representation Two'
The MSB represents the sign bit (0 = positive, 1 = negative) To calculate the negative number:
1. 2. Two's Complement Example Two'
N = 8: from 128(10000000) to 127 (01111111)] 128(10000000) (01111111)] Complement all bits of the positive number Add 1 010 =
B = 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 step 1 step 2 For nbit number the decimal value = n
n  2 b i 2 i i = 0  b n  1 2 n  1 + 1 The range for nbit is: n from 2n1 to +2n1 1. Advantages: Addition/subtraction performed directly and Advantages: only one zero Disadvantage: One extra negative number (not symmetric) Disadvantage:
CSE261 C2 #23 #23 1 0 0 0 0 0 0 0 0 = 010 10 CSE261 C2 #24 #24 Numerical Systems and Codes 6 CSE261 Spring 2008 Two's Complement Exercise Two' One's Complement Representation One'
The MSB represents the sign bit (0 = positive, 1 = negative) To calculate the negative number, complement all bits of the positive number For nbit number the decimal value = n +10010 = step 1 64 32 16 0 1 1 0 1 0 0 1 8 0 1 4 1 0 2 0 1 1 0 1 step 2 B = + 1 1 0 0 1 1 1 0 0 = 10010 n  2 b i 2 i i = 0  b n  1 ( 2 n  1  1 ) The range for nbit is: from 2n1 1 to +2n1 1. nAdvantages: Symmetry. The ease of complementation. Advantages: Symmetry. Disadvantages: Two possible representations of zero. Disadvantages: Complicated digital adders. adders. CSE261 C2 #25 #25 CSE261 C2 #26 #26 One'sComplement Example One'
N = 8: form 127(10000000) to 127 (01111111) 127(10000000) +10010 = 0 1 1 0 0 1 0 0 10010 = 1 0 0 1 1 0 1 1
Decimal
8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7
CSE261 C2 #27 #27 Comparison (4bit) (4Signed Magnitude One's One' Compl. Compl. Two's Two' Compl. Compl.
1000 1111 1000 1001 1110 1001 1010 1101 1010 1011 1100 1011 1100 1011 1100 1101 1010 1101 1110 1001 1110 1111 0000 or 1000 0000 or 1111 0000 0001 0001 0001 0010 0010 0010 0011 0011 0011 0100 0100 0100 0101 0101 0101 0110 0110 0110 0111 0111 0111
CSE261 C2 #28 #28 010 = 0 0 0 0 0 0 0 0 010 = 1 1 1 1 1 1 1 1 Numerical Systems and Codes 7 CSE261 Spring 2008 Exercise
What is the representation of +11, 11 in: +11, 5bit signed magnitude representation +11 = 0 1 0 1 1 11 = 1 1 0 1 1 Two's Complement Addition (A+B) Two'
1. 2. Use binary addition rules. Ignore any carry beyond the sign bit If the range is not exceeded addition result will be correct including the sign bit . 5bit one's complement representation one' +11 = 0 1 0 1 1 11 = 1 0 1 0 0 Examples: (2) + (4) (1 1 1 0 1 1 0 0 (3) + (+3) (0) 1 1 0 1 0 0 1 1 5bit two's complement representation two' +11 = 0 1 0 1 1 11 = 1 0 1 0 1
CSE261 C2 #29 #29 (6) 1 1 0 1 0 1 0 0 0 0
CSE261 C2 #30 #30 Addition overflow
Overflow detection rule: Two's Complement Subtraction: Two' Method 1 (ab) (a1. 2. The sign bit of the sum is different from the sign bit of the two addends Or, The carry in (Cin) and the carry out (Cout) of the sign bit (Cin) (Cout) are different Example: (4) + (5) (9) 0 1 0 0 0 1 0 1 1 0 1 0
Overflow
CSE261 C2 #31 #31 Use binary Subtraction rules Ignore any borrow beyond the sign bit Example:
(4) + (5) (1 1 0 0 1 0 1 1 (2)  (4) (2) 1 0 1 1 1
CSE261 C2 #32 #32 0 0 1 0 0 1 0 0 1 1 1 0 Numerical Systems and Codes 8 CSE261 Spring 2008 Two's Complement Subtraction Two' Method 2 (a+(b)) (a+(Add A to the Two's complement of B: Two'
1. 2. Two's Complement Subtraction Two' Take the One's complement of B One' Add it to A with initial carryin 1 carryCarry in 1 0 0 1 0 + (2) 1 0 1 1 1 1 1 0
CSE261 C2 #33 #33 Overflow detection rule: The sign bit of the result is different from the Example: 24 22 sign bit of A and the two's complement of B two' One's Complement of 4 One' CSE261 C2 #34 #34 Exercise
Do the following in 7 bit two's complement arithmetic: two' (35) + (42) (51) 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 1 12  56 0111000: (56) 1000111 + 1 1001000: (56) ((12) + (56) (1 1 1 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0
CSE261 C2 #35 #35 Coding
Coding: Representing a set of objects by a set of Coding: strings. Code: The set of bit strings. Code: Code Word: A particular bit string in the Code. Word: Examples: Data Objects: Decimal Numbers, Characters. Objects: Nondata Objects: Machine states, Control Actions. Objects:
CSE261 C2 #36 #36 Overflow Numerical Systems and Codes 9 CSE261 Spring 2008 Binary Codes For Decimal Numbers
To represent the 10 decimal digits we need 4 bits. Examples: 0 1 2 3 4 5 6 7 8 9
CSE261 C2 #37 #37 Decimal Codes
Decimal BCD BCD (8421) 2421 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 0000 0001 0010 0011 0100 1011 1100 1101 1110 1111 Excess3 Biquinary Excess0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 0100001 0100010 0100100 0101000 0110000 1000001 1000010 1000100 1001000 1010000 1outof10 out of1000000000 0100000000 0010000000 0001000000 0000100000 0000010000 0000001000 0000000100 0000000010 0000000001
CSE261 C2 #38 #38 4 bits Codes
1. 2. 3. BCD (8421)  Binary Coded Decimal 2421 Excess3 ExcessBiquinary (7 bits) 1outof10 (10 bits) out of Other Decimal codes
1. 2. Exercise
Codes for 517 BCD: 2421: Excess3: Excess Gray Code
One bit changes between two successive code words Binary Code and Gray Code (n = 3): 0101 0001 0111 1011 0001 1101 1000 0100 1010 Decimal 0 1 2 3 4 5 6 7 BinaryCode 000 001 010 011 100 101 110 111 GrayCode 000 001 011 010 110 111 101 100 Application: Electromechanical applications Application:
CSE261 C2 #39 #39  The Mechanical Encoding disk. Altimeters. CSE261 C2 #40 #40 Numerical Systems and Codes 10 CSE261 Spring 2008 Binary Code to Gray Code Conversion
Convert n bit Binary code into n bit Gray Code: Bit i of the Gray Code is obtained by comparing bits i and i+1 of the Binary Code: Add If Exercise
i and i+1: same 0; else, 1 extra 0 to the left of the Binary code Binary 11101 011101 1 0 0 1 1 Gray bits i and i+1 in the Binary code are the same then bit i of the Gray code is 0, else bit i is 1. Gray 1 0 0 1 1 0 1 1 1 0 1 Binary Example: Binary 10011 010011 1 1 01 0 Gray CSE261 C2 #41 #41 CSE261 C2 #42 #42 Character Codes
Each character is represented by a bit string ASCII  the American Standard Code for Information Interchange. Characters Contains ASCII Table
b6b5b4 b3b2b1b0 0000 0001 0010 0011 1111 The Code for a is 1100001 1100001
CSE261 C2 #43 #43 CSE261 C2 #44 #44 000 001 010 011 100 101 110 111 SP ! " # 0 1 2 3 @ A B C ` a b c are encoded into 7 bits strings
letters 128 characters:
BCD uppercase and lowercase Numbers punctuation marks control characters Numerical Systems and Codes 11 CSE261 Spring 2008 Codes for nondata objects
n objects encoded with b=log2n=log10n/log102 binary bits. Example: 124 objects, b=7 Coding for Error Control Bit error occurs due to noise, etc., if
0 1 Application: The control unit runs one device at a time. Control Unit Enable? DEVICE Binarycoded device select Binary sent is received as 1 or sent is received as 0 EDC (error detecting codes) to detect bit errors
Enable? DEVICE Enable? DEVICE
CSE261 C2 #45 #45 ECC (error correcting codes) to correct bit errors
CSE261 C2 #46 #46 EDC: repetition2 code repetitionTo send: send: If we receive 10110 To send: send: ECC: repetition3 code repetition10110 1100111100 1000001101 111000111111000 110000100001001 If we receive we detect two errors but miss one Detects any one bit error in a 2bit block, but will miss two 2 we correct two and miss two.
Detects any 1 bit error in a 3bit block, but will miss any 2 or 3 3 CSE261 C2 #47 #47 CSE261 C2 #48 #48 Numerical Systems and Codes 12 CSE261 Spring 2008 ECC vs. EDC
Sender Paritybit EDCs ParityReceiver
if s=0, then 0 (or 2 or 4 or ...) bit s=0, errors occurred, no error. if s=1, then 1 (or 3 or 5 or ...) bit s=1, errors occurred. compute s = r1 r2 ... rm rm+1 When r1, r2, ..., rm, rm+1 is received b1, b2, ..., bm, p
Information Bits Evenparity Code Oddparity Code EDC uses fewer extra bits to detect errors than ECC EDCs are used to catch almost all errors. To send m bits, b1, b2, ..., bm. Send m+1 bits, b1, b2, ..., bm, p, where p = b1 b2 ... bm (b1 b2 ... bm p = 0) the Internet. ECCs are used when retransmission would take too long or where some errors can be tolerated. high BW, teleconferencing.
P(2 or 4 or ... errors)= P (undetected errors) small enough for independent bit errors
CSE261 C2 #49 #49 T a b le 2  1 3 Distance2 codes with three information bits. 000 001 010 011 100 101 110 111 000 0 001 1 010 1 011 0 100 1 101 0 110 0 111 1 000 1 001 0 010 0 011 1 100 0 101 1 110 1 111 0 CSE261 C2 #50 #50 Errordetection Error Coding Terminology
Codewords for parity bit codes: 2m of possible 2m+1 binary
strings of length m+1 that can be sent. Error detection: use a dictionary of code words that detection: is a subset of the 2n possible code words
A failure occurs when an invalid code word is sent Given any collection of codewords, the smallest number of codewords, bits that must be in error for one codeword to be changed into another is called the Hamming distance d of the code. (Use to find d) Paritybit codes always have d=2. ParityA code with Hamming distance d is guaranteed to detect any d1 bit errors. errors. CSE261 C2 #51 #51 CSE261 C2 #52 #52 Numerical Systems and Codes 13 CSE261 Spring 2008 Example
Four valid codewords: codewords: 0000000000 0000011111 1111100000 1111111111 ECC: Hamming Codes
3 1 Choose codewords which are all d or more apart, d = 2k+1 for some k. Hamming Distance d = 5 it can detect 4 bit errors it can correct double errors When k or fewer bit errors occur they can be corrected. corrected.
For each 4 data bit b1b2b3b4 send also 3 parity bits: If 0000000111 arrives, the original must be 0000011111. 0000011111. what if triple error occurred?
CSE261 C2 #53 #53 x1 = b1 b2 b4 x2 = b1 b3 b4 x3 = b1 x4 = b2 b3 b4 x5 = b2 x6 = b3 x7 = b4 x1, x2, x3, x4, x5, x6, x7 s0 = x1 x3 x5 x7 s1 = x2 x3 x6 x7 s2 = x4 x5 x6 x7 s0 = s1 = s2 = 0 7 bits to correct 1 error in 4 data bits. CSE261 C2 #54 #54 ECC: Hamming Codes
Ta bl e 2  1 4 Code words in distance3 and distance4 Hamming codes with four information bits.
MinimumDistance3 Code MinimumDistance4 Code Information Bits ECC: Hamming Codes
Word sizes of distance3 and distance4 Hamming codes. distancedistanceMinDistance3 Min Distancecodes Info bits 1 4 11 26 57 120 Parity Bits 2 3 4 5 6 7 Total Bits 3 7 15 31 63 127 MinDistance4 Min Distancecodes Parity Bits 3 4 5 6 7 8 Total Bits 4 8 16 32 64 128 Code words in distance3 and distance4 distancedistanceHamming codes with four information bits. Information Bits Parity Bits Parity Bits 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 000 011 101 110 110 101 011 000 111 100 010 001 001 010 100 111 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0000 0111 1011 1100 1101 1010 0110 0001 1110 1001 0101 0010 0011 0100 1000 111155 CSE261 C2 #55 # CSE261 C2 #56 #56 Numerical Systems and Codes Receiver If s2s1s0 = 0, then no error. 0, error. If s2s1s0 = i , xi is in error. Sender 14 CSE261 Spring 2008 CRC
CRCs (Cyclic Redundancy Codes) are commonly used. Represent a binary string of length m as a polynomial of degree m (or less) 110110 CRC
Choose a generator polynomial, G(x), in advance. G(x), (CRC16: x16+ x15+ x2+1. CRCCCITT: x16+ x12+ x5+1) CRC 16: CRC CCITT: Codewords with corresponding polynomials as divisible by G(x). G(x). Sender
1. Represent lengthm message as m1 order lengthmpolynomial bm1xm1 + .. + b0x0 : M(x) 2. Append r (= the degree of G(x)) zeros to the loworder end of the block: xrM(x) lowM(x) 3. Find remainder by dividing xrM(x) by G(x): M(x) R(x) 4. Find checksummed block [xrM(x)R(x)] [x M(x)R(x) and transmit it: T(x) [divisible by G(x)] Receiver
If remainder = 0, then accept it, else reject. Single bit error: E(x) = xi i th bit is in error. Divide it by G(x): T(x)/G(x) + E(x)/G(x) : 1x5+1x4+0x3+1x2+1x1+0x0 = x5+x4+x2+x1 CRCs use mod2 polynomial arithmetic: mod Add (or subtract) 2 bitstrings (or polynomials) using XOR. bit T(x) + E(x)
CSE261 C2 #57 #57 CSE261 C2 #58 #58 CRC
CRC16 and CRCCCITT are 16bit checksum CRCCRC16 Summary
Binary forms used in digital systems Positive/Negative Arithmetic catches all single and double errors, all errors with an odd number of bits, all burst errors of length 16 or less, almost all 17bit , 18bit, or longer error bursts. 1718 numbers, addition/subtraction operations performed directly on negative numbers represented in Two's complement. Two' Hexadecimal numbers are used for shorthand representation of binary numbers. Decimal numbers, characters, and actions encoded into binary strings. Errordetecting and errorcorrecting codes use extra bits. Errorerror CSE261 C2 #59 #59 CSE261 C2 #60 #60 Numerical Systems and Codes 15 ...
View
Full
Document
This note was uploaded on 05/08/2008 for the course CSE 261 taught by Professor Ercanli during the Spring '08 term at Syracuse.
 Spring '08
 Ercanli

Click to edit the document details