About the Binary and Hex Calculator
This calculator works on two numbers at a time. Pick the number system you want to type in, enter A and B, choose an operation, and the answer appears in binary, octal, decimal and hexadecimal together. Add, subtract, multiply, divide with remainder and modulo use unlimited-size whole numbers, so nothing wraps around. The bitwise operations AND, OR, XOR, NAND, NOR, XNOR, NOT and the two shifts use the bit width you select, from 8 to 64 bits, and the answer is also shown as a signed two's complement value. Only whole numbers are supported: there are no fractions or floating-point binary.
Updated September 2026
How to use the Binary and Hex Calculator
- 1Choose Binary, Octal, Decimal or Hexadecimal for the numbers you will type.
- 2Enter A, pick an operation, and enter B (NOT only needs A).
- 3For bitwise work, set the bit width: 8, 16, 32 or 64.
- 4Read the result in all four systems and, for bitwise operations, the bit-by-bit columns.
- 5Copy any of the four forms with its Copy button.
Arithmetic in binary and hex
Binary and hex arithmetic follow the same rules as decimal, only with different digits. In binary you carry when a column reaches 2. In hex you carry when a column reaches 16, so F + 1 is 10. Division truncates toward zero and the remainder takes the sign of A, so −100 divided by 7 is −14 with remainder −2.
Subtraction can give a negative answer. It is written with a minus sign in every system and, in the two's complement panel, as the bit pattern a computer would store.
Bitwise operators explained
- AND keeps a bit only if both inputs have it: useful for masks.
- OR sets a bit if either input has it: useful for turning flags on.
- XOR sets a bit when the inputs differ: useful for toggling flags.
- NOT flips every bit inside the chosen width.
- NAND, NOR and XNOR are AND, OR and XOR followed by NOT.
- Shift left multiplies by 2 for each place, and shift right divides by 2, dropping the remainder.
Bit width and two's complement
A bit width fixes how many binary digits a value has. In 8 bits there are 256 patterns. Read as unsigned they mean 0 to 255; read as signed two's complement they mean −128 to 127. The same pattern 11111111 is 255 unsigned and −1 signed, which is why the result panel shows both.
For NOT, shifts and the logic operations, the calculator first turns each input into its pattern of the chosen width, works on the bits, and returns the unsigned value. Widen the width if an input does not fit.
Common uses: masks and flags
Programmers use AND with a mask to pick out part of a value, for example 0xFF to keep the lowest byte, or 0x0F to keep the lowest four bits. OR adds a flag, and XOR flips it. If you only need to convert one number to another base, the Number Base Converter is quicker, and the Binary Translator turns text into ones and zeros. For everyday sums, the Online Calculator has the usual keys.
Features
- Add, subtract, multiply, divide with remainder and modulo
- AND, OR, XOR, NAND, NOR, XNOR, NOT and shifts
- 8, 16, 32 and 64-bit widths
- Result in binary, octal, decimal and hex at once
- Signed two's complement view of the result
- Bit columns that line A, B and the result up
- Accepts 0b, 0o and 0x prefixes, spaces and underscores
- Runs in your browser
Frequently asked questions
How do I add two binary numbers?
Choose Binary, type both numbers, and pick Add. Column by column, 0 + 0 is 0, 1 + 0 is 1, and 1 + 1 is 10, which writes 0 and carries 1. For example 1010 + 0110 is 10000, which is 10 + 6 = 16 in decimal.
What is two's complement?
It is the usual way computers store negative whole numbers. In an 8-bit pattern the top bit counts as minus 128, so 11111111 is −1 and 10000000 is −128. The panel under each result shows the signed value and the bit pattern for the width you chose.
How do I do bitwise AND, OR and XOR?
Line the two numbers up bit by bit. AND gives 1 only where both bits are 1, OR gives 1 where either is 1, and XOR gives 1 where they differ. With A = 1100 and B = 1010, AND is 1000, OR is 1110 and XOR is 0110.
How do I subtract hexadecimal numbers?
Choose Hexadecimal, type both numbers and pick Subtract. Borrowing works with sixteens instead of tens. If B is bigger than A the answer is negative, such as −3 for 5 minus 8, and the two's complement panel shows how that looks in bits.
What happens when a shift goes past the bit width?
You cannot shift by the full width or more here: the shift amount must be from 0 to one less than the width, or you get an error. Bits pushed off the left end of a left shift are dropped, so 255 shifted left by 7 in 8 bits leaves 128. A right shift is logical, so zeros come in from the left.
How do I convert between binary, decimal and hex?
Type the number in one system and pick any operation, such as Add with B set to 0. The result lists all four bases. For conversion on its own, the Number Base Converter also handles any base from 2 to 36.
Does the bit width change addition and multiplication?
No. Those operations use unlimited-size integers, so 2^63 plus 2^63 is exactly 2^64, without wrapping. The width only affects the bitwise operations, the shifts and the two's complement panel, where a value too big for the width shows its lowest bits.