Modulo 2 operation

Modulo 2 operation is a binary algorithm that does not consider carry and borrow, that is, modulo 2 addition is binary addition without carry, and modulo 2 subtraction is binary subtraction without borrow.

1. Modulo 2 addition

Two sequences are added modulo two, that is, the corresponding bits in the two sequences are added without carry, the same is 0, and the difference is 1.

1+1=0 0+0=0 1+0=1 0+1=1 (the same is 0, otherwise it is 1)

E.g:

    0 1 0 1

+ 0 0 1 1

──────
   0 1 1 0


2. Modulo 2 Subtraction

Subtraction, like addition, operates according to the addition rules.

0-0=0 1-1=0 0-1=1 1-0=1 (the same is 0, otherwise it is 1)

E.g:

 0 1 1 0
-0 0 1 1
──────

 0 1 0 1


3. Modulo square method

Multi-bit binary modulo 2 multiplication is similar to multi-bit binary multiplication in the ordinary sense, or decimal multiplication. The difference is that the latter uses addition with carry when accumulating intermediate results (or partial products), while modulo 2 multiplication uses modulo 2 addition for processing intermediate results.

0×0=0 0×1=0 1×0=0 1×1=1 (except 11 which is 1, the rest are 0)

E.g:

    1 0 1 1
       × 1 0 1
  ——————
     1 0 1 1
  0 0 0 0

  1 0 1 1

——————

 1 0 0 1 1 1


4. Modulo 2 division

Multi-bit binary modulo 2 division is also similar to multi-bit binary division in the ordinary sense, but the two use different rules on how to determine the quotient. The latter is based on binary division with borrow, and determines whether the quotient is 1 or 0 according to whether the remainder is sufficient to subtract the divisor. If it is sufficient, the quotient is 1, otherwise the quotient is 0. Multi-bit modulo 2 division uses modulo 2 subtraction, binary subtraction without borrowing, so it is meaningless to consider whether the remainder is sufficient to subtract the divisor. In fact, in the CRC operation, the first digit of the divisor is always guaranteed to be 1, so the quotient of the modulo-2 division operation is determined by the modulo-2 division operation result of the first digit of the remainder and the first digit of the divisor. Because the first digit of the divisor is always 1, according to the modulo 2 division algorithm, the quotient of 1 is 1 when the first digit of the remainder is 1, and the quotient is 0 when it is 0.

在下面的示例中,当余数位数与除数位数相同时,才进行异或运算,余数首位是1,商就是1,余数首位是0,商就是0。当已经除了几位后,余数位数小于除数,商0,余数往右补一位,位数仍比除数少,则继续商0,当余数位数和除数位数一样时,商1,进行异或运算,得新的余数,以此至被除数最后一位。

例如:

1111000 除以1101,模2除法的商为1011,余数为111.


#第一步  

1111000  

1101  

0010000 ----余数,商为1,只要第一位非0商就是1  

#第二步,每步移一位,当起始位为0时,除以0;为1时除以除数。  

010000  

0000  

010000  ----余数,商为0,只要第一位是0商就是0  

#第三步  

10000  

1101  

01010  -----余数,商为1,这里的余数你猜出,其实就是对应位异或  

#第四步  

1010  

1101  

0111   ------余数,商为1,如果位数比除数还小,不再继续运算  

#最终余数为111,商为1011  




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325857007&siteId=291194637