Understanding the binary calculator — concept and principle
This calculator performs arithmetic and bitwise operations on binary numbers of any length: addition, subtraction, multiplication, whole-number division with remainder, AND, OR and XOR. Results are shown in binary, decimal and hexadecimal, along with the calculation in decimal so you can check it.
How it is calculated
Inputs are read as whole numbers in base 2 (optional minus sign; spaces and underscores ignored).
+, −, × follow normal arithmetic.
÷ gives a quotient truncated toward zero and a remainder with the sign of the first number: first = quotient × second + remainder.
AND, OR, XOR compare bits: 1 AND 1 = 1; 1 OR 0 = 1; 1 XOR 1 = 0.
- Negative numbers take part in bitwise operations in two's complement form, as in most programming languages.
The principle
Binary is a place-value system like decimal, but each place is worth a power of 2 instead of 10. Any arithmetic rule that works in decimal also works in binary, with carries and borrows at 2 instead of 10. Long division in binary is especially simple, because each step either subtracts the divisor (quotient bit 1) or does not (quotient bit 0). Bitwise operations treat each bit position separately, which is how programs set, clear or test individual flags.
Worked example
Default inputs: 1101 0110 ÷ 1011.
- 1101 0110 in decimal = 128 + 64 + 16 + 4 + 2 = 214.
- 1011 in decimal = 8 + 2 + 1 = 11.
- 214 ÷ 11 = 19 remainder 5, so 214 ÷ 11 = 19.
- Quotient in binary = 10011 (hexadecimal 13), which has 5 bits.
- Remainder in binary = 101 (decimal 5); check: 19 × 11 + 5 = 214.
How to read the result
Use the decimal check line to confirm the operation. The hexadecimal form is convenient for programmers because each hex digit stands for four bits. For bitwise operations, line the numbers up at the right and compare bit by bit: AND keeps bits set in both, OR keeps bits set in either, and XOR keeps bits that differ.
Common mistakes
- Expecting a fractional result from division; the quotient is a whole number.
- Forgetting that AND, OR and XOR work on bits, not on decimal digits.
- Reading binary from left to right without place values.
- Assuming remainders are always positive; here they follow the sign of the first number.
Frequently asked questions
How do I convert binary to decimal?
Add the place values (1, 2, 4, 8 …) for every position that holds a 1.
What is XOR used for?
Toggling bits, simple checksums and comparing two values bit by bit.
Why is division truncated toward zero?
That is how integer division works in many programming languages, including JavaScript BigInt.
How is hexadecimal related to binary?
Each hex digit represents exactly four binary digits.
Sources: D. Tarnoff, Computer Organization and Design Fundamentals (East Tennessee State University), Chapter 3 "Binary Math and Signed Representations" · ECMAScript Language Specification, BigInt division (truncation toward zero)