Binary modulo 2 division (CRC check)

Binary modulo 2 division is not the same as binary division.

Modulo 2 arithmetic: addition does not carry, subtraction does not borrow.

Binary division:

       Binary division with borrow bits determines whether the quotient is 1 or 0 based on whether the remainder is subtracted by the divisor. If it is enough, the quotient is 1, otherwise the quotient is 0.

Binary modulo 2 division:

      uses modulo 2 subtraction, without borrowing binary subtraction, so it makes no sense to consider whether the remainder is enough to subtract the divisor or not. In fact, in the CRC operation, it is always guaranteed that the first bit of the divisor is 1, so the quotient of the modulo 2 division operation is determined by the result of the modulo 2 division operation of the first bit of the remainder and the first bit of the divisor. Because the first digit of the divisor is always 1, according to the modulo 2 division algorithm, thenif the first digit of the remainder is 1, the quotient is 1, and if the remainder is 0, the quotient is 0.

(1) Step-by-step calculation method:

    Modulo 2 division is similar to long division, but has one feature: no borrowing. To put it bluntly, it is bitwise XOR, the same is 0, and the difference is 1. 
It has three principles: 
   1. The divisor and the highest digit of the dividend (the same digit as the divisor) are XORed, and the quotient is 1. (The first digit of the divisor must be 1) 
   2. Remove the first digit of the remainder first. If the highest digit of the remainder is 1, the quotient is 1, and continue to divide modulo 2 using it as the divisor. 
         If the highest bit is 0, then the quotient is 0 and repeat step 2. 
   3. When the remainder digits are less than the divisor digits, the operation ends. 

(2) After becoming familiar with the rules, a relatively simple method

      1. When the number of digits in the remainder is the same as the number of digits in the divisor, the XOR operation is performed. The first digit of the remainder is 1, and the quotient is 1. The first digit of the remainder is 0, and the quotient is 0. .

      2. After several digits have been divided, the remainder is smaller than the divisor, and the quotient is 0. The remainder is padded to the right by one digit. If the number of digits is still less than the divisor, the quotient will continue to be 0. , when the number of digits in the remainder is the same as the number of digits in the divisor, the quotient is 1, and an XOR operation is performed to obtain a new remainder, from which the last digit of the dividend is reached.

 

 

 

Guess you like

Origin blog.csdn.net/weixin_39450145/article/details/83987836