Binary Calculator
Type two binary numbers, pick an operation, and the answer arrives with the working that produced it. Addition draws the carry out of each column over the column it lands in, subtraction draws each borrow over the column that lent it, multiplication draws one partial product for every 1 in the second number, and division prints the quotient and the remainder on separate lines: 101 + 11 is 1000, which is 8, and 1010 divided by 11 is 11 remainder 1. Every value is an arbitrary-precision integer from the moment it is read to the moment it is printed, so an operand of up to 4,096 binary digits comes back exact and 2^53 + 1 is 9007199254740993 rather than the even number a calculator working in doubles returns. Switch on a fixed width of 4, 8, 16, 32 or 64 bits and the same bits can be read as unsigned or as signed two's complement: 11111111 is 255 one way and -1 the other. A result that does not fit the width is shown wrapped with an overflow flag raised and the exact answer printed beside it, so 1111 + 1 at four bits is 0000 and the panel still says the true answer is 10000. AND, OR, XOR, NOT and both shifts sit on the same row of buttons. Nothing is uploaded, nothing needs an account, and the only thing kept is your last entry in this browser.
carry 1 1 1
1 0 1 = 5
+ 1 1 = 3
------------
1 0 0 0 = 8
decimal 8 hex 0x8 octal 010
overflow none bits used 4101 + 11 = 1000, which is 8 in decimal, written in 4 bits. Unsigned with no fixed width, so the answer is a plain binary number and nothing was dropped.
Column addition from the least significant bit, with the carry out of each column drawn over the column it lands in. No fixed width: the operands are whole binary numbers of any length, and nothing wraps.
Each box takes binary digits only, and spaces, underscores and an 0b prefix are read rather than refused, so 1010 1010 and 0b10101010 are the same number. With the width on Auto there is no register to fall out of: the numbers are whole integers of any length up to 4096 digits a box, and a subtraction that goes below zero comes back with a minus sign. Pick a width and the same bits become a register: Unsigned reads them as a magnitude, Signed reads the top bit as a sign, and an answer that does not fit is shown wrapped with the overflow flag raised and the exact answer printed beside it. For the two shifts the second box holds the number of places, written in binary like everything else. The column grid is drawn whenever every row fits 24 columns and no minus sign is involved; past that the same rows are printed without the grid. Your entry is kept in this browser so the page opens where you left it.
Common questions
- How do you add two binary numbers by hand?
- Line the two numbers up on the right and work from the last column to the first, exactly as in decimal, except that the only sum that carries is 1 + 1. Take 101 + 11. The last column is 1 + 1, which is 0 carry 1. The next is 0 + 1 plus that carry, which is 0 carry 1 again. The next is 1 + 0 plus the carry, 0 carry 1, and that final carry becomes the leading digit: 1000, which is 8. This page draws that carry row above the sum, so the three carries are on screen rather than in your head.
- What does 11111111 mean in binary?
- It depends on how wide the number is and whether it is signed, which is why the width and the mode are settings here rather than assumptions. Read as an unsigned byte, 11111111 is 255. Read as a signed 8-bit value in two's complement, the top bit is the sign, so the same eight bits are -1. Set the width to 8 and switch between Unsigned and Signed to see both readings of one pattern. The two corners work the same way: 01111111 is 127 in both readings, and 10000000 is 128 unsigned and -128 signed.
- What happens when the answer does not fit the bit width?
- The bits wrap the way a register wraps, and the page says so rather than letting you read a wrong number as a right one. At four unsigned bits, 1111 + 1 is 0000, because the carry out of the top column has nowhere to go. The Overflow cell turns to Yes, the panel prints the exact answer 10000 beside the wrapped one, and the note says it kept the low 4 bits. With the width set to auto there is no register to overflow, so the same sum is simply 10000.
- How does binary division work on this page?
- It is integer division, truncated toward zero, and the remainder comes back with the quotient instead of being thrown away. 1010 divided by 11 is 10 divided by 3, so the quotient is 11, which is 3, and the remainder is 1. Both lines are printed under the rule, and the identity that checks them is the one you would use on paper: quotient times divisor plus remainder equals the number you started with. Dividing by zero is refused with a message that names the box to change, because no answer exists to show there.
- What do AND, OR, XOR and NOT do to a binary number?
- They work one column at a time with no carries at all. AND puts a 1 where both numbers have a 1, OR where either does, and XOR where exactly one does, so 1100 XOR 1010 is 110, which is 6. NOT flips every bit, which is why it needs a fixed width: with no width there is no last bit to flip. Choosing NOT while the width is on Auto moves the width to 8 bits rather than leaving you on a refusal, and setting the width back to Auto then says plainly what is missing. At 8 bits, NOT 00001111 is 11110000, which is 240 unsigned. The two shifts are here too, and the second box holds the number of places written in binary like everything else, so 11 there means three places and 101 shifted left gives 101000, which is 40.
- How large a binary number can it handle?
- Up to 4,096 binary digits in each box, which is far past any register you are likely to be checking, and the arithmetic stays exact the whole way. Nothing is converted to a floating-point number at any point, so 2^53 + 1 comes back as 9007199254740993 rather than the 9007199254740992 a calculator built on doubles returns. Paste something longer than the limit and the page says how long it was and what the limit is instead of quietly cutting it. Fixed widths go up to 64 bits, and the auto setting has no width at all.
- Is a negative answer wrapped or signed?
- With no fixed width it is signed: 11 minus 101 is 3 minus 5, so the answer is -10, which is -2, written with a minus sign because there are no bits to wrap into. With a fixed width it wraps, because that is what a register of that size does: the same subtraction at four unsigned bits is 1110, which is 14, and the overflow flag is raised with the exact answer, -10 in binary, printed beside it. Both behaviours are on screen with a label, so neither one can be mistaken for the other.
Exact integer arithmetic on arbitrary-precision integers, so a long operand is never truncated or turned into a floating-point number. Unsigned is the default and a negative result is labelled as such. Fixed-width mode reads the same bits as two's complement and raises an overflow flag instead of wrapping quietly. Division is integer division and the remainder is shown beside it.