Elecmetric

Binary Calculator

Add, subtract, multiply, divide, AND, OR, XOR and shift binary, octal, decimal or hexadecimal numbers, with the answer in all four bases.

Binary0001 0001
Octal21
Decimal17
Hexadecimal11
Bits in the answer5
Remainder (divide only)

Worked examples

SumEntered inBinaryDecimalHexadecimal
1011 + 110binary100011711
1111 0000 AND 1010 1010binary10100000160A0
FF − 0Fhexadecimal11110000240F0
1000 ÷ 7decimal100011101428E
1 << 8decimal100000000256100

Binary arithmetic rules

Addition: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1). Subtraction borrows from the next column: 10 − 1 = 1. Multiplication is shifted copies of A added together, one for each 1 bit in B. Division is repeated subtraction with a whole quotient and a remainder.

Bitwise operations

ABA AND BA OR BA XOR B
00000
01011
10011
11110

Where engineers use it

Register masks, status flags and protocol frames in PLCs, meters and relays are written in binary or hexadecimal. A mask such as 0x0F keeps the low four bits of a byte, which is an AND with 00001111, and a status word is tested bit by bit the same way.

Frequently asked questions

How do I add binary numbers?

Add column by column from the right, as in decimal, but 1 + 1 = 10: write 0 and carry 1. For 1011 + 110, the columns give 1 + 0 = 1, 1 + 1 = 0 carry 1, 0 + 1 + 1 = 0 carry 1, 1 + 1 = 0 carry 1 and a final 1, which is 10001 (decimal 17).

What do AND, OR and XOR do?

They work on each bit position separately. AND gives 1 only if both bits are 1, OR gives 1 if either bit is 1, and XOR gives 1 if exactly one of the two bits is 1. Masks and flag tests in registers use AND and OR; XOR toggles bits.

What does a shift do?

Shifting left by one bit position doubles the number and shifting right halves it, dropping the lowest bit. Shifting left by 8 multiplies by 256, which is moving a value up one byte.

Does it handle negative numbers and two's complement?

Add, subtract, multiply and divide accept a minus sign and show a signed answer such as -1010. It does not show two's complement bit patterns, and AND, OR, XOR and shifts need non-negative numbers.

How big can the numbers be?

Up to 200 digits in each entry. The arithmetic is exact, with no rounding, because it uses whole-number (BigInt) arithmetic rather than floating point.

Related

Number Base ConverterScientific Notation ConverterSI Prefix ConverterScientific CalculatorConversion Centre

Tell us how to improve this page

This opens your email app. Nothing is sent until you press send.