"Abby" <ab*****@yahoo.com> wrote in message

I have an array which contain Hex no. in each position.

I would like to know what is the algorithm to do the 2's

complement for 8 bits checksum, and how can I write the code for it.

Two's complement is a way of representing negative numbers in binary.

Instead of having a bit which acts as a negative "flag", we invert, and then

increment.

So 1 is 0000 0001 int binary

inverting gives 1111 1110

incrementing gives 1111 1111 or -1 in two's complement.

The nice thing is that by adding, and discarding the overflow, we get the

correct answer.

0000 0001 = 1

+1111 1111 = -1

=1 0000 0000

discard the overflow and we get 1 + -1 = 0;

A checksum is a technique to check data for transmission errors or

tampering. If the last few bytes are the sum of all the preceding bytes,

then any errors are likely to be detected.

The problem is that "two's complement checksum" doesn't have a definite

meaning that I'm aware of. It obviously has something to do with taking the

two's complement of a number somewhere, and presumably each byte contributes

to the final answer, but you will have to ask further what exactly is meant

by the term.