Emmanuel Delahaye <emdelYOURBRA@noos.fr> scribbled the following:[color=blue]
> In 'comp.lang.c',
abbkung@yahoo.com (Abby) wrote:[color=green]
>> checksum value at data[4] is the checksum calculated from data[0] -
>> data[3]. I would like to know what is the algorithm to do the 2's
>> complement for 8 bits checksum,[/color][/color]
[color=blue]
> How is this a C question?[/color]
[color=blue]
> "Add 1 and invert the bits."[/color]
No. "Invert the bits and add 1". If you do it the other way around,
you end up with the wrong result. Let's use eight-bit values for
simplicity. The 2's complement of 0 (binary 00000000) should also be 0.
First we add 1 (result binary 00000001) and then we invert the bits:
result binary 11111110. If we do it the right way, we first invert the
bits (result binary 11111111) and then add 1: result binary 00000000,
due to a wrap-around.
[color=blue][color=green]
>> and how can I write the code for it.
>> I'm still a newbie. Please advise. Thank you.[/color][/color]
[color=blue]
> Do your best, and we will check your code.[/color]
Certainly his best can be better than your best... =)
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
|
http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"As we all know, the hardware for the PC is great, but the software sucks."
- Petro Tyschtschenko