|
-
March 10th, 2003, 03:55 AM
#1
Checksum
Hello!
I have a 8-char-string for which I have to do a checksum. Which would be the best way to do it? I thought of a kind of a weighted sum like:
sum = char[0]*1+char[1]*2+char[2]*3+char[3]*4+char[4]*5+char[5]*6+char[6]*7+char[7]*8 % 255;
But this could not alarm if (for example):
char[0]: Original: 0 Fault transmitted: 2
char[1]: Original: 2 Fault transmitted: 0
Is there a better way?
-
March 10th, 2003, 05:35 AM
#2
The situation that two values have an error that cancels each other is very low.
Cheksums makes just that, it makes the possibility of error not null, but much lower than without checksum.
There are some better algorithms, there are algorithms that finds and corrests an error, but I never used them.
-
March 10th, 2003, 08:11 AM
#3
Is it a requirement that you use a checksum? That hardly seems worthwhile for an 8-byte transmission, since most checksum algorithms will require at least 2 bytes. If you really want to be sure the 8 bytes have been correctly received, the easiest thing to do is to keep transmitting them until the receiver gets the same string twice.
But if the requirement is to use checksumming (for whatever reason), you are correct in that a simple sum such as you propose will fail if there are two (or more) compensating errors. One solution to this would be to consider the 8-byte string as a number, then select some other number - say 11 - and use it to divide the 8-byte number; the remainder would form a one-byte checksum of sorts.
There are all sorts of methods out there for ensuring that data gets transmitted correctly. Check out this reference for an interesting discussion.
Regards
Robert Thompson
-
March 10th, 2003, 08:24 AM
#4
Hi TSYS,
thanx for your answer. Yes the checksum is needed because the string represents a barcode. So you would prefer a division instead of a sum? I will have a look at the link.
One last question: I'm not quite sure what a remainder is (sorry, my english...):
Example: 7/3
Is the remainder
1 (% or mod)
or
2 (7/3 = 2.33333 is rounded 2).
-
March 10th, 2003, 08:58 AM
#5
if you want to read more about Checksums I can email you quite a lot of docs.
-
March 10th, 2003, 08:58 AM
#6
"Remainder" refers to what's left over after a division, so the remainder of 7/3 (also referred to as REM( 7/3 ) ) would be 1, and the remainder of 7/4 would be 3. The C++ "modulo" operator - % - returns the remainder of the division.
If you're working with bar codes, isn't the last byte already a checksum? I thought that was how they worked....
Regards
Robert Thompson
-
March 10th, 2003, 09:22 AM
#7
Hi Myth, thanks, I'll check TSYS link out and come back to you if needed.
Hi TSYS: Yes, the barcode itself has a checksum, but it's not very strong and it's only for the barcode-reader. If someone gives in the barcode in a keyboard (for example because the code is damaged), there is no checksum at all.
-
August 21st, 2012, 03:42 AM
#8
-
August 21st, 2012, 04:55 AM
#9
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|