Hi,
I have a question regardning modulo 0xFFFF.
In my program which is a C program I read from a file a long XML string that is ended by checksum value.
When I read the requirement I shall read all characters from the string and add them to a total sum and then perform a modulo 0xFFFF. For me it will be the wrong checksum.
Are there anybody that can help me with a C source code to perform this kind of functionality?
BR
Big Spender
Sam HobbsPosted Feb 9, 2023, 5:05 AM
I think you will need to be more specific about the format of the data.
Henri HeinPosted Feb 8, 2023, 2:37 AM
I am not sure what exactly you are asking. Are you asking how to take the modulus of 0xFFFF? That's simple enough. If your result is in r, you use
As you describe your problem, I suspect there is either a problem with the encoding when you 'add them to the total sum' (presumably the ASCII or UCS-2 value of the characters) or with the length. You have to add the character values using the proper encoding, and you have to count the correct number of characters. The character count is important if there are extra line endings, an EOF marker, or any other extra input at the end of the character stream.