Calculating 8 bit checksum from a series of bytes?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 27
Joined: Tue May 06, 2008 5:33 am
Contact:

Calculating 8 bit checksum from a series of bytes?

Post by tcbcats » Mon Nov 23, 2020 12:48 am

I am doing some serial communication and need to calculate a 8 bit (one byte) checksum by adding up a series of 10 bytes.
I have been able to do it but when the checksum value goes over 255 is keeps counting up and ends up in a 16 bit value.
I need the 8 bit value to roll over from FF and keep the checksum result in a 8 bit value that just keeps rolling over to 00 when he count reaches FF.
I there a simple way to do this?
tcbcats

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Calculating 8 bit checksum from a series of bytes?

Post by dunbarx » Mon Nov 23, 2020 4:40 am

Hi,

Can you (pseudo)

Code: Select all

put checkSumValue mod 255 into checkSumValue
This will roll over, where 254 = 254, 255 = 0 and 256 = 1.

Craig

tcbcats
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 27
Joined: Tue May 06, 2008 5:33 am
Contact:

Re: Calculating 8 bit checksum from a series of bytes?

Post by tcbcats » Tue Nov 24, 2020 9:02 pm

Thanks it worked... had to set 255 to 256 in order the keep the correct count sequence.
tcbcats

Post Reply