In: Computer Science
UDP and TCP use 1s complement for their checksums. Suppose you have the following three 8-bit bytes: 01010011, 01100110, 01110100.
a) What is the 1s complement of the sum of these 8-bit bytes? (Note that although UDP and TCP use 16-bit words in computing the checksum, for this problem you are being asked to consider 8-bit sums.)
b) Why is it that UDP takes the 1s complement of the sum; that is, why not just use the sum?
c) With the 1s complement scheme, how does the receiver detect errors? Is it possible that a 1-bit error will go undetected? How about a 2-bit error?
The given binary-words are 01010011, 01100110, 01110100
(a) the sum is...
Add the first two binary-words...
0 1 0 1 0 0 1 1
+ 0 1 1 0 0 1 1 0
---------------------------------
1 0 1 1 1 0 0 1
Add the result to the third binary-word...
1 0 1 1 1 0 0 1
+ 0 1 1 1 0 1 0 0
---------------------------------
1 0 0 1 0 1 1 0 1
Carry 1....
Add the carry to the last significant digit of the sum
0 0 1 0 1 1 0 1
+ 1
----------------------------------
0 0 1 0 1 1 1 0
Invert all bits of the result i.e 1's to 0's and 0's to 1's to find the 1's compliment...
1's compliment of the sum is... 1 1 0 1 0 0 0 1
(b)
Reason why UDP takes 1's compliment of the sum is...
--> 1's compliment of the sum gives the checksum of UDP , but the only sum doesn't give the checksum of UDP.
(c)
To detect the errors , receiver adds four words including the checksum , result should be all bits 1. If it has a single zero then receiver knows that there is an error...
1-bit error will never go undetected, but 2-bit error can go undetected , like if the last digit of the 1st word is converted to 0 and the last digit of the 2nd word is converted to 1.