From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-12-2018 07:44 AM
Hi,
I have to calculate the checksum using the function below. I am new to Labview and my c skills is a little rysty. Please help.
Thankyou.
24 bit = 00001 + 0000000000000000000
Var1 (5bit msb)
Var2 (19bit)
Encoded little endian 32 bit from 0x1FFFC to 0x1FFFF
uint32_t checksum8(const void *buf, uint32_t length)
{
uint32_t n, checksum=0;
uint8_t *p = (uint8_t *)buf;
for (n=0; n <length; n++)
{
checksum += *p++;
if (checksum > 255) checksum -= 255;
}
return (~checksum&0xff);
Combined number = checksum * 16777216 + Var1 * 524288 + Var2
08-12-2018 12:02 PM
08-12-2018 03:43 PM
I'd use a quotient and remainder
08-13-2018 12:16 AM - edited 08-13-2018 12:18 AM
08-13-2018 02:22 AM - edited 08-13-2018 02:23 AM
08-13-2018 06:02 AM
Seems like a strange choice of algorithm for the checksum.
In a normal world, for an 8 bit checksum, you would get the byte array and use sum array elements on it (the result would be limited to 8 bits and would all be fine).
In this case, each time you overflow the 8 bits you effectively need to discard the overflowed bit add 1 to the checksum.
It doesn't add any robustness to the checksum algo, and feels to me like a mistake.
How sure are we that the c++ code actually works?
0xDEAD
08-13-2018 09:02 AM
@GerdW wrote:
Hi Jeff,
some more explanation (too late to edit previous post):
- "(checksum > 255)" refers to a Q&R with 256 as divider…
- "checksum -= 255" refers to a Q&R with 255 as divider…
Sorry, I should have been specific. Tha line is equivalent to
checksum = 256 mod (checksum);
Or, just use a U8 😄 and no math required.
You know where to post your example.
Better you than Christian. 😄
08-13-2018 09:56 AM
Hi Jeff,
I don't get your math…
How is
checksum = 256 mod (checksum);
equivalent to
if (checksum > 255) checksum -= 255;
???
Example:
checksum := 270 (before math routine).
Your result: checksum = (256 mod 270) = 256
OP wanted: checksum = 270-255 = 15
08-13-2018 10:03 AM - edited 08-13-2018 10:06 AM
256 mod (270) is 14. Modulus is the remainder of the dividend ,270 / divisor, 256.
My C++ may be rusty but, is that a bad thing for a LabVIEW guy?
08-13-2018 10:07 AM
@GerdW wrote:
Hi Jeff,
I don't get your math…
How is
checksum = 256 mod (checksum);equivalent to
if (checksum > 255) checksum -= 255;???
Example:
checksum := 270 (before math routine).
Your result: checksum = (256 mod 270) = 256
OP wanted: checksum = 270-255 = 15
Jeff's nomenclature is backwards. It really should be:
checksum mod 255
That would match what the OP stated. If you just add bytes and ignore the overflow (the way much checksums work), it would be a mod 256.