Ora

How to get remainder in binary?

Published in Binary Division 2 mins read

To get the remainder in binary division, you perform a process similar to long division in the decimal system. The key is to compare the dividend (the number being divided) to the divisor (the number you're dividing by) at each step. The reference text describes this process.

Here's a breakdown of how to find the remainder in binary division:

  1. Comparison: Look at the leftmost bits of the dividend. Start with just enough bits to be potentially greater than or equal to the divisor.

  2. Quotient Bit:

    • If the selected bits of the dividend are greater than or equal to the divisor, write a '1' in the quotient. (As the reference text states, "Add the number 1 in the quotient place.")
    • If the selected bits of the dividend are less than the divisor, write a '0' in the quotient. You may need to consider more bits from the dividend in this case.
  3. Subtraction: If you wrote a '1' in the quotient, subtract the divisor from the selected bits of the dividend. (As the reference text states, "Then subtract the value, you get 1 as remainder").

  4. Bring Down: Bring down the next bit from the dividend to the remainder you obtained in the previous subtraction.

  5. Repeat: Repeat steps 2-4 until all bits of the dividend have been processed. (As the reference text states, "Repeat the process until the remainder becomes zero by comparing the dividend and the divisor value."). The final result of the subtraction process, after all bits have been brought down and processed, is the remainder.

Example:

Let's divide 1101 (dividend) by 101 (divisor).

Step Operation Quotient Remainder
1 Compare 110 with 101. 110 >= 101 1
2 Subtract 101 from 110 1 1
3 Bring down the next bit (1) 1 11
4 Compare 11 with 101. 11 < 101 10 11
5 No more bits to bring down.

Therefore, 1101 / 101 results in a quotient of 10 (2 in decimal) and a remainder of 11 (3 in decimal).

Table Summary:

Operation Description
Comparison Compare a portion of the dividend to the divisor.
Quotient Bit Determine whether to add a '1' or '0' to the quotient.
Subtraction Subtract the divisor from the dividend portion if the quotient bit is '1'.
Bring Down Bring down the next bit from the dividend.
Repeat Repeat the process until all dividend bits are processed.