9.8 An Algorithm for Error Detection
9.8.1 When implementing error detection, it is convenient to imagine a checksum for each individual character
position. This partial checksum forms a check on all preceding characters, as well as the present character. Then
using Horner’s Rule, one can calculate a running checksum (that is, calculate each partial checksum in order). This
leads to the following algorithm.
9.8.2 Add the checksum (or the previous character position to itself (for the first character position, the value of the
previous checksum is zero). If the result is 59 or greater, subtract 59. This leaves a value in the range 0–58.
9.8.3 Add the result of step 1 to itself. If the result is 59 or greater, subtract 59.
9.8.4 Add the result of step 2 to itself. If the result is 59 or greater, subtract 59. The result of this step is eight times
the previous position checksum, modulo 59.
9.8.5 Add the result of step 3 to the numerical value of the character in the present position. If the result is 59 or
greater, subtract 59. The result of this step is the checksum for the present character position.
9.8.6 Repeat steps 1 through 4 for each character position. If the checksum for the final character position is
nonzero, an error has occurred.
An Algorithm for Error Detection
最新推荐文章于 2024-05-21 17:42:44 发布