It is many years since I have had to work with this sort of maths, so if
anyone can help, even if just to refresh my understanding of 2's-complement
and modulo-256 concepts, I would appreciate it greatly.
Please email me directly if possible.
Regards,
Nick Alexander
>Can anyone help? I need to calculate a 2 byte checksum that is a
>two's-complement of a modulo-256 addition of a series of bytes in a data
>string, such that summing the data bytes and the checksum (modulo-256) will
>result in a value of zero.
- Add all the bytes together
- find the remainder from a division by 256 (this is known as taking
the modulo). Eg, in C:
remainder = sum % 256;
- negate the number (which, in the MSDOS world, is equivalent to
taking the two's complement):
remainder = -remainder;
My only question is, why is the checksum two bytes? The upper one
would always be 0FF hex. (255 decimal)
Davin.
__________________________________________________________
*** davmac - sharkin'!! dav...@iname.com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/
Thanks for the info. As to the two bytes, this is what is specified in the
data stream from the measuring device that I am gathering data from.
Possibly the programmer was allowing for some other use of this space at a
later stage?
Regards,
Nick Alexander
Hello Guys,
The most feaseble explanation is that those two bytes are ment for either
a simple checksum (as you have done), or space for a 16-bit CRC (Cyclic
Redundancy Check), which is a method that will grab more errors, and even
(with the right calculations) repair some of them. Youre not, by chance,
working on a Z-modem protocol ?
Greetz,
Rudy Wieser
It's a data recorder with a "LAN" mode which allows up to 30 devices to
paralleled onto an RS485 interface, so I need to read and write to the
devices.
Regards,
Nick Alexander