starcorn
starcorn

Reputation: 8551

How is checksum used for error detection

This is going probably be a general question regarding checksum used for error detection. I got a lab assignment where we are going to recreate a protocol similar to how RDT2.0 works. And I'm stuck in how to use checksum to detect errors.

The functions are there already what I need is to implement the functionality. What I don't understand is how you can know that a pack is corrupted.

E.g. I'm going to send over a text file. So I have some function which will take a number of bytes and store it in an object where I'll also attach a header with the checksum.

So if this package will be corrupted now I have no where to tell it has happent since the checksum will also be changed right?

So can anyone tell me how I should use the checksum?

Upvotes: 2

Views: 2410

Answers (4)

krishna shetty
krishna shetty

Reputation: 1

The 2's complement of the checksum is transmitted instead of checksum itself. The receiver wil accumulate all the bytes including the 2's complement of the checksum. If there is no error, the content of the accumulator should be zero after accumulation of the 2's complement of the checksum byte.

Upvotes: 0

nmichaels
nmichaels

Reputation: 51019

I think the missing bit is that the checksum is calculated before you send the data, then recalculated after the data is received. If the checksum of the received data matches the received checksum in the attached header, you can be fairly confident that neither was corrupted en route.

Upvotes: 0

Epcylon
Epcylon

Reputation: 4727

The checksum might have been changed, but the chances of it being changed to match the checksum of the changed content are slim.

So, when you read the package, you calculate a new checksum for the content and compare it to the checksum stored in the package. If they match, there is no corruption, if not, something was changed (either the content, the checksum, or both).

Upvotes: 3

Carl Norum
Carl Norum

Reputation: 225142

You're right that if your data gets corrupted, your checksum might be too - the hope is that they don't get corrupted in a way that's not apparent to you. A simple parity bit is the worst for this sort of transparent corruption - the larger your checksum field, the less likely it is that your data will be corrupted and you won't notice.

Upvotes: 0

Related Questions