Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checksum, two's-complement, Modulo-256 calculations

3,502 views
Skip to first unread message

Nick Alexander

unread,
Aug 31, 1999, 3:00:00 AM8/31/99
to
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.

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


Davin McCall

unread,
Aug 31, 1999, 3:00:00 AM8/31/99
to
On Tue, 31 Aug 1999 13:02:50 -0700, "Nick Alexander"
<al...@iafrica.com> wrote:

>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/

Nick Alexander

unread,
Aug 31, 1999, 3:00:00 AM8/31/99
to
Hi Davin,

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

Caisson

unread,
Sep 1, 1999, 3:00:00 AM9/1/99
to
Nick Alexander <al...@iafrica.com> schreef in artikel
<7qh8b8$ej$1...@nnrp01.ops.uunet.co.za>...
> Hi Davin,

>
> > My only question is, why is the checksum two bytes? The upper one
> > would always be 0FF hex. (255 decimal)
>
> 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?

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


Nick Alexander

unread,
Sep 1, 1999, 3:00:00 AM9/1/99
to
Hi Rudy,

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

0 new messages