Binary division
Binary long division compares the divisor against the value from the left.
Each step writes 1 when the divisor fits and 0 when it does not.
The value 1010 divided by 0011 gives 11, with a remainder of 1.
Try binary division in the bit editor
The quotient of 1010 and 0011. Edit the expression or select a bit to flip it.
7
6
5
4
3
2
1
0
3
value · 8 bits · unsigned
- binary
- 0b00000011
Binary division step by step
Divide 1010 by 0011:
- Take the first bit, 1. The divisor 11 does not fit. Write 0.
- Take 10. The divisor 11 does not fit. Write 0.
- Take 101. The divisor 11 fits once, and 101 less 11 leaves 10. Write 1.
- Bring down the last bit to get 100. The divisor fits once, and 100 less 11 leaves 1. Write 1.
- The quotient is 11, which is 3, and the remainder is 1.
A division by a power of two is a shift
| Expression | Shift | Effect |
|---|---|---|
| x / 2 | x >> 1 | Half, remainder dropped |
| x / 4 | x >> 2 | A quarter, remainder dropped |
| x / 8 | x >> 3 | An eighth, remainder dropped |
| x % 8 | x & 7 | The remainder alone |
| x % 2 | x & 1 | The lowest bit, which is 1 for an odd value |
Where binary division is used
A processor without a divider needs many cycles for a division, so firmware avoids it.
A conversion from a raw reading to a unit often divides by a power of two.
A ring buffer takes the remainder of the index, which is an AND when the size is a power of two.
Binary division: points to note
- Beetwise drops the remainder, so 1010 divided by 0011 gives 3 rather than 3.33.
- A right shift divides by a power of two and drops the remainder as well.
- A right shift of a negative value keeps the sign, so it does not match a division for every value.
- A division by zero has no result. The expression stays invalid.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about binary division
- What is 1010 divided by 0011 in binary?
- The quotient is 11, which is 3, and the remainder is 1.
- Why does a right shift divide by two?
- Every bit moves to the next lower position, and each position holds half the one above it.
- How do I get the remainder with bitwise operations?
- Apply AND with the divisor less one, when the divisor is a power of two. For 8, apply x & 7.