原帖由 rollin7 于 2009-9-3 21:53 發(fā)表
實際上求的是各個16位的反碼之和,采用的是反碼加法,即把所有16位數(shù)累加求和再取反
sum=(sum>>16)+(sum&0xffff); //高16位加上低16位
sum=sum+(sum>>16); //執(zhí)行以上加法后,sum有可能在17位上有進位,再 ...
Modular sum
A variant of the previous algorithm is to add all the "words" as unsigned binary numbers, discarding any overflow bits, and append the two's complement of the total as the checksum. To validate a message, the receiver adds all the words in the same manner, including the checksum; if the result is not a word full of zeros, an error must have occurred. This variant too detects any single-bit error, but the probability that a two-bit error will go undetected is a little less than 1/n.
原帖由 OwnWaterloo 于 2009-9-4 10:41 發(fā)表
http://en.wikipedia.org/wiki/Checksum
歡迎光臨 Chinaunix (http://www.72891.cn/) | Powered by Discuz! X3.2 |