Binary arithmetic and bitwise calculations
This binary calculator performs addition, subtraction, AND, OR and XOR on two nonnegative whole numbers entered in base two. Choose the operation and read the updated result in binary. It is useful for checking carries, comparing a bit mask with arithmetic, and verifying a small part of a digital logic or programming exercise.
The calculator uses exact integer operations instead of converting inputs to ordinary floating-point numbers. Long bit patterns therefore do not lose low bits through numeric rounding or get truncated to a signed machine word during bitwise operations. Each input may contain up to 4096 binary digits. The page does not multiply, divide, shift, convert fractions or automatically create parity bits.
Enter binary numbers and read the output
Use the digits 0 and 1 without a binary prefix, decimal point or minus sign in the input fields. Leading zeros are allowed and do not change the value. Surrounding whitespace is ignored, while an empty input or other characters produce a visible error rather than being silently interpreted as a different number.
Results are written without unnecessary leading zeros. That is ordinary integer notation, not a statement that a hardware register changed width. If an exercise requires a specific word size, add the appropriate leading zeros when recording a nonnegative result. This tool does not implement selectable register widths, overflow flags or automatic wraparound.
Subtraction can produce a negative answer. It is displayed with a minus sign before the binary magnitude, so the sign is explicit. That representation is not a fixed-width two’s-complement bit pattern. To encode the same negative value for a processor register, you would need to choose the register width and apply that encoding separately.
Worked example: the same inputs, five operations
Start with the default operands A = 1010 and B = 1100. The following results come from the same calculation library used by the interactive page.
| Operation | Binary result |
|---|---|
| ADD | 10110 |
| SUBTRACT, A minus B | −10 |
| AND | 1000 |
| OR | 1110 |
| XOR | 110 |
The subtraction answer is negative because A is smaller than B. Reversing the operands gives 10 instead. The XOR result is shown as 110; for a four-position written comparison, that same nonnegative value can be recorded as 0110. The extra leading zero changes the formatting, not the underlying result.
Now try A = 1111 and B = 1 with ADD. The result is 10000 because carries propagate through the occupied positions into a new leading position. The calculator keeps that carry rather than wrapping to a shorter word. This is helpful when checking arithmetic by hand, but different from a fixed-width CPU instruction that discards bits beyond its register.
Addition and subtraction rules
In binary addition, a column can produce a sum bit and a carry into the next position. That carry is why arithmetic combines information across columns. Subtraction similarly uses borrowing when a position does not contain enough value to subtract the corresponding bit. These are numerical operations on the complete operands.
The result of A minus B depends on operand order, while addition gives the same sum after swapping them. Check which field is A before interpreting a subtraction result. If the intended task uses a particular complement method, distinguish that handwritten method from the integer answer: this page reports the answer but does not show a carry or borrow trace.
When comparing an answer with decimal working, convert the operands and result separately using the same interpretation of the sign. This page presents a binary output rather than a decimal, octal or hexadecimal result panel.
Bitwise AND, OR and XOR rules
Bitwise operations align the operands at the right and compare corresponding positions independently. AND keeps a one only where both operands have a one. OR produces a one where either operand has a one. XOR produces a one where the two bits differ. There is no carry or borrow between positions for these operations.
For A = 1010 and B = 110, mentally align B as 0110. AND gives 10 after leading zeros are removed, while ADD gives 10000 for the same two inputs. This comparison shows why bitwise logic cannot be substituted for arithmetic even when an expression uses the same binary strings.
Use the logic gate simulator to check the individual bit rules with toggles. For a Boolean expression involving multiple variables and operators, use the truth table generator. These are related tasks, but they answer different questions from integer arithmetic.
Common mistakes and limits
Do not paste a decimal number and assume the calculator will convert it. Non-binary digits produce an error. Do not expect a prefix to be required: the inputs already specify base two. Also distinguish a negative subtraction result from an unsigned wrapped result; the page intentionally reports the mathematical signed difference.
For masking applications, decide the required width before padding or encoding values. Leading zeros can matter to a written packet or register format even though they do not change an integer. For networking practice, the CIDR calculator applies related bitwise ideas to address ranges, while this page stays focused on the selected operation and two input operands.