15

enter image description here

I have attached an image showing a Modulo 2 binary division.

I can roughly understand the working below which is using XOR calculation but I am not sure how the answer (in red) is being computed based on the workings.

I have searched the net and couldn't find any good step by step guide to solve this binary long division.

Hope someone can enlighten me.

Withhelds
  • 175
  • 3
    It looks like you are XORring as opposed to subtracting. This means that you are doing long division in the ring of polynomials of binary coefficients ($\Bbb{F}_2[x]$). This is the operation that is needed e.g. when doing CRC-checks. But it is not to be confused with division of integers in base 2. The example is doing polynomial arithmetic, because if it were integer division, you should be borrowing at some steps. – Jyrki Lahtonen Feb 19 '14 at 16:51
  • Yup it is based on XOR, I have updated my question title. – Withhelds Feb 19 '14 at 16:56
  • 2
    See this question and its answers for another worked out example. – Jyrki Lahtonen Feb 19 '14 at 17:01
  • 3
    You are calculating $x^{11}+x^{10}+x^9+x^6+x^4$ divided by $x^4+x^3+x+1$ in the ring $\Bbb{F}_2[x]$. The quotient is $x^7+x^5+x^3+x^2$, and the remainder is $x^2$. The LSB is the constant term, the next bit the coefficient of the linear term ($x^1$) and so forth. – Jyrki Lahtonen Feb 19 '14 at 17:09

3 Answers3

2

Each bit is the highest order bit of what remains so far, right shifted by four places because the dividend has highest term $2^4$. So the first bit is $1$ (as always). Because the first subtraction results in a $0$ in the next column, the second bit of the quotient is $0$. It is just like base $10$ division, if you get a zero in the next column over you put a zero in the quotient and skip it. Try dividing $\frac {100100}{99}$

Ross Millikan
  • 383,099
  • I have updated my question and it is based on XOR. – Withhelds Feb 19 '14 at 16:57
  • 1
    My answer is based on XOR. As I understand it, you are asking how to determine each bit of the quotient. In XOR division, you just look at the leading bit at each stage. The first zero in the quotient comes because of the leading zero in the fourth line (including the quotient). The second comes because of the leading zero in the sixth line. The last two come from the two leading zeros in the tenth line. In regular binary division, you would have a zero any time the current remainder is less than the dividend. – Ross Millikan Feb 19 '14 at 17:12
  • 1
    Thanks, I have managed to understand :) – Withhelds Feb 20 '14 at 08:19
1

Addition, subtraction, and XOR are all equivalent in this case:

A quick note: this a follow up to Ross Millikan as well as a couple other comments to bring together a few of the ideas and make it more accessible to non-mathematicians.

  1. as Jyrki Lahtonen noted, the above style of "binary division" is likely from a computer science method of error correction called Cyclic Redundancy Check (CRC).
  2. this is not normal binary division. As mark has noted the "subtractions" also appear to be xor operations.
  3. I'm not 100% sure if there is a proper mathematical name for this, but in computer science you will see stuff like: binary polynomial division over a finite field, etc. (In CRC we are actually interested in the modulo/remainder not the quotient)

The finite field part is the important point. In each subtraction operation that makes up the "division," the subtraction is over the finite field of 0 and 1 for that one binary digit.

For integer values over this finite-field size (0 and 1 are the only possibilities) addition, subtraction, and XOR are all equivalent functions. For most inputs this is intuitive. However, for 1 + 1 and 0 - 1, given the finite field it is necessary to loop around to the other side of the finite-field:

1 + 0 = 1
1 - 0 = 1
1 XOR 0 = 1

1 + 1 = 2 (or 10 with the carry in binary) but over the finite field this one greater than the largest value in the field maps back to the first value value in the field so zero
1 - 1 = 0
1 XOR 1 = 0

0 + 1 = 1
0 - 1 = -1 but again since we are one less than the minimum value in the finite field this maps to the largest value in that field so one
0 XOR 1 = 1

Just like mathematicians, computer science people arbitrarily define certain operations in certain contexts for their usefulness, or to enable further level of abstraction: Think of the "addition" or "multiplication" operations in Elliptical Curve Cryptography.

With that in mind, in the context of CRC, it is perfectly legitimate to call this "binary division"

1

First of all, this is XOR not subtraction. Similar bits being XOR'ed always equal 0, different bits (no matter the order) in an XOR always equal 1. 0 XOR 0 = 0, 1 XOR 1 = 0, 1 XOR 0 = 1, 0 XOR 1 = 1. Once you have grasped this firmly, it makes the math easier and behaves very similarly to traditional long division as far as having leading zero's in the dividend, put a 0 in the quotient and shift the divisor over one.

A 1 is placed above the 5th bit like in regular long division to mark the place of the last character of the Divisor. If we follow the bits in order the first part is 11100 XOR 11011 Bit1 1 XOR 1 = 0 Bit2 1 XOR 1 = 0 Bit3 1 XOR 0 = 1 Bit4 0 XOR 1 = 1 Bit5 0 XOR 1 = 1

This gives you a remainder of 0111. Since there is a leading 0 in the dividend the divisor gets shifted over again and a 0 is placed above the 6th bit.

This process is repeated until the divisor's last bit is in line with the dividend's last bit. If there is a leading 0 in the dividend place a 0 over the last bit in the dividend, if there is not a leading 0, place a 1 and do the math.

Important to note: once the last XOR math has been calculated, the remainder is your Modulo.

mark
  • 11