On the proof of Hamming calibration error correction algorithm

Source: Internet
Author: User

First say what the Hamming algorithm is.

No original documents have been checked, so the original definitions and proofs have not been seen. According to the <<structure computer organization>>, which is now on hand, the instructions in the book.

The Hamming algorithm can establish a correction code for any length of memory (note that it is not only possible to verify errors, but also to correct them). The principle is as follows:

Assuming that the original data has M-bits, the R-bit is added to the M-bit data, and the word length of the m+r bit is obtained. In this m+r bit, all 2 bits of an integer power are test bits, others are data bits (note that the bits here are counted from 1, not 0).

Each check bit can verify a specific bit.

For example, a 16-bit word would need to include a 5-bit check digit, i.e. 1th, 2, 4, 8, 16 bits are check bits. At this point the actual word length reaches 21 bits. The first check digit is responsible for inspecting 1th, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, and the second check digit is responsible for verifying 2nd, 3, 6, 7, 10, 11, 14, 15, 18, 19 ...

Specific as follows:

The 1th person is responsible for the inspection: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21

The 2nd person is responsible for the inspection: 2, 3, 6, 7, 10, 11, 14, 15, 18, 19

The 4th person is responsible for the inspection: 4, 5, 6, 7, 12, 13, 14, 15, 20, 21

The 8th person is responsible for the inspection: 8, 9, 10, 11, 12, 13, 14, 15,

The 16th person is responsible for inspection: 16, 17, 18, 19, 20, 21

So, how do you know that a test bit is responsible for examining which bits?

The setting principle of the Hamming check code is that the B-bit is usually examined by the b1,b2,b3,..., BJ bit, wherein B=B1+B2+B3+...+BJ.

For example, the 5th bit is checked (5=1+4) by the 1th and 4th bits, and the 6th bit is checked together by the 2nd bit and the 4th bit (6=2+4).

To illustrate the error correction process, here is a hypothetical 16-bit word:

1 1 1 1 0 0 0 0 1 0 1 0 1 1 1 0

Assuming the even test is used, the 21-bit words obtained after adding the 1th, 2, 4, 8, 16-bit check codes are as follows:

(even test is to adjust the test bit according to the number of bits 1, so that the total number of 1 digits is an even number)

0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1 0

Assuming the fifth bit goes wrong, it becomes:

0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1 0

Then, the test bit 1 and the test bit 4 is located in the test column of the number of 1 is not an even number, so we know the error.

At this point, just know which one is wrong and you can correct it back.

There are two ways to know which one is wrong:

The first one is a comparative analysis. For example, in the above example, because the 1th test bit and the fourth verification of the queue are all wrong, then the dislocation must be their common, and other queues do not. Compare it and you'll know it's the 5th place.

The second method is to add the test bits of the error queue and get the dislocation. In the example above, 1+4=5.

It is necessary to note that this algorithm corrects the premise that it assumes that the number of errors is 1 bits. That is, if the wrong 3 bits, this algorithm will also think that it only one error (wrong 2 bits will not be tested, because the parity Hamming code is 2)

We already know it can be checked and corrected, but why? How to ensure the correctness of this algorithm?

If you want to prove it, the first natural question is: the principle of setting the check code according to the Hamming algorithm (that is, the B-bit is usually examined by the b1,b2,b3,..., BJ bit, where b=b1+b2+b3+...+ BJ.), how to ensure that for each bit in the code word, there are some check bits, these check bits added to get this bit? For example, in the example above, which bits should be examined by the 17th bit? Since 17 is relatively small, we are very easy to know 17=1+16 and thus know should be tested by 1th and 16th place. But the Hamming algorithm can test any number of bits, what if the bit is large? 1000? 1000000? 1000292? Obviously cannot enumerate all.

Furthermore, how do you know that the check bit is unique based on the principle of setting the check bit according to the Hamming algorithm? That is, for the above 17, we already know 17=1+16, but how do we know that there will be no other of the three = M + n? Of course, because 17 is very small, we can enumerate, know there is no other possibility, but if that bit is very large? 1000? 10000000? 1232312312? Obviously, it cannot be enumerated and must pass a rigorous mathematical proof.

Let's start by proving these two problems. Having proved the two problems, the whole proof is almost complete.

The proof is as follows:

First, the Hamming algorithm sets the check bit principle: all 2 bits of an integer power are check bits (that is, the 1th, 2, 4, 8, 16, 32 ... bits).

The obvious point is that each single digit is not greater than the maximum value of those existing check bits, for example, 21 bits of the above example, even the largest 21, will not be larger than the 1+2+4+8+16. Because, given a number n, if 2^r < n < 2^ (r+1) (here, < <32), then n must be less than 2^0 + 2^1 + 2^2 + ... + 2^r, because this geometric series equals 2^ (r+1) minus 1. and N < 2^ (r+1), i.e. n <= 2^r-1.

Well, under the assumption of 2^r < n < 2^ (r+1), prove one point, that is, if you want to have a formula, 2^i + 2^j + .... + 2^k = N, then, there will definitely be 2^r, because, if there is no 2^r, even 2^0, 2^1, 2^2 ...... 2^ (r-1) all add up also only 2^r–1 (geometric series sum), let alone n, because 2^r < n < 2^ (r+1). So if you want to have a sum of 2 of the whole number of powers, and it's n, it must have a 2^r

On top of that, we assume that there is a formula:

2^i + 2^j + ... + 2^r= n

That is, some 2 of the whole number of powers plus equals N. It also shows that one must be 2^r. where 2^r < n <2^ (r+1)

Now Bashi to do a transformation, to:

2^i + ... + 2^j = n–2^r

(formally, N is replaced by n–2^r)

Now, make M=n–2^r

Now we're going to prove that there is a sum of 2 of the power of the whole number, and it equals m:

2^i + ... + 2^j = m

Since M=n–2^r, while 2^r < n <2^ (r+1), then you can know 0 < m < 2^r

The left side of the 2^i and 2^j range is 0 ~ 2^ (r-1). So the transformation then goes back to the previous n situation. The difference is that the range of n is 2^r < n < 2^ (r+1), and the range of M is 0 < m < 2^r.

But in fact, the essence has not changed. We can still find a Q that makes 2^q < M < 2^ (q+1). And this m is still in those remaining 2^i ... Within the range of the sum of the 2^j, this goes back to the exact same situation as the previous n.

So, as you can see, in this way, subtracting a power of 2 from N continuously, you can get one and only one sum, so that it and N

i.e. 2^i + 2^j + ... + 2^r= n

Mathematically, this is called Mathematical induction:)

Above we prove that for any one bit n, there is only one and the same formula makes 2^i + 2^j + ... + 2^r= n

That is, that bit n has the only test bits I and J and ... and R

So, when we find that something goes wrong, we know that the test bits I and J and ... Adding to R gives you a misplaced position (that is, N). This is the error correction method of the Hamming calibration algorithm.

The strict proof will not be written. It is difficult to solve the formatting problems of text, so it is difficult to write.

Proof of the Hamming checksum error correction algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.