Home/Math/Binary Calculator

Binary Calculator

Binary arithmetic, bitwise operations and conversions between binary, decimal, hexadecimal and octal — with exact results at any size.

Quick Answer: How Does Binary Work?

Binary is base 2, using only the digits 0 and 1. Each position is worth twice the one to its right, so 1101 means 8 + 4 + 0 + 1 = 13. Computers use binary because a transistor has two reliable states, on and off. Enter one or two binary numbers below to add, subtract, multiply, divide, apply bitwise operations, or convert between bases.

Binary Calculator

Binary accepts only 0 and 1. Spaces and a 0b prefix are ignored, so 1111 0000 and 0b11110000 both work. Any other character is rejected rather than silently trimmed.

Keyboard: Enter calculates · Esc clears

Result
Binary sum
11000
13 + 11 = 24 in decimal
Why the input validation matters. Many binary tools use a parsing function that stops at the first character it does not recognise. Type 1012 and it silently returns 5 — the value of 101 — with no warning. This calculator rejects the input and tells you which character was wrong.

What Is Binary?

Binary is the base-2 number system. Where decimal uses ten digits (0–9) and each place is worth ten times the one to its right, binary uses just two digits (0 and 1) and each place is worth twice the one to its right.

value = … + d₃×2³ + d₂×2² + d₁×2¹ + d₀×2⁰
1101 = 1×8 + 1×4 + 0×2 + 1×1 = 13

A single binary digit is a bit. Eight bits make a byte, which can hold 256 different values (0 to 255). Four bits are sometimes called a nibble, which is convenient because one nibble maps exactly to one hexadecimal digit.

Why Computers Use Binary

A transistor is reliably either conducting or not. Distinguishing two states is easy and robust; distinguishing ten voltage levels would be error-prone, especially as components age or heat up. Binary also maps directly onto Boolean logic — true and false — which is what makes logic gates possible.

Binary Place Values

Bit position76543210
Power of two2⁷2⁶2⁵2⁴2⁰
Decimal value1286432168421
Example: 110100001101

To read a binary number, add up the place values wherever there is a 1. For 1101 that is 8 + 4 + 1 = 13.

Converting Between Bases

The two methods

Binary → decimal: add the place values where a 1 appears.
Decimal → binary: divide by 2 repeatedly, then read the remainders bottom to top.
Binary → hex: group into 4 bits from the right, convert each group.
Binary → octal: group into 3 bits from the right, convert each group.

Decimal 13 to binary

13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read the remainders upward: 1101

Binary 11111111 to hex

Group into fours: 1111 1111
1111 = F, 1111 = F
= FF (which is 255 in decimal)

Binary Arithmetic Rules

addition: 0+0=0 · 0+1=1 · 1+0=1 · 1+1=10 (carry 1)
subtraction: 0−0=0 · 1−0=1 · 1−1=0 · 0−1=1 (borrow)
multiplication: 0×0=0 · 0×1=0 · 1×0=0 · 1×1=1

Binary addition works exactly like decimal addition, except you carry at 2 instead of at 10. Multiplication is easier than in decimal, because each partial product is either a copy of the number or all zeros.

Addition: 1101 + 1011

  1101  (13)
+ 1011  (11)
= 11000  (24)

Multiplication: 1101 × 1011

13 × 11 in decimal is 143
= 10001111 in binary

Bitwise Operations

OperationRule1100 op 1010Typical use
AND (&)1 only if both bits are 11000Masking — keeping selected bits
OR (|)1 if either bit is 11110Setting flags
XOR (^)1 if the bits differ0110Toggling bits, checksums, simple ciphers
NOT (~)Flips every bitdepends on bit widthInverting a mask
Left shift (<<)Moves bits left, multiplying by 2 each place1100 << 1 = 11000Fast multiplication
Right shift (>>)Moves bits right, dividing by 2 each place1100 >> 1 = 110Fast division

NOT needs a bit width. Flipping every bit of 1010 gives a different answer depending on whether you are working in 8, 16, 32 or 64 bits, because the leading zeros flip to ones. In 8-bit, NOT 00001010 is 11110101. This calculator asks you to choose the width rather than assuming one.

XOR has a useful property: applying it twice returns the original value. That is why it appears in simple encryption, in parity checks, and in the classic trick for swapping two variables without a temporary one.

Signed Binary and Two's Complement

Plain binary has no minus sign, so computers represent negative numbers using two's complement: invert every bit, then add 1. The leading bit then acts as a sign bit — 0 for positive, 1 for negative.

−5 in 8-bit two's complement

5 in binary: 00000101
Invert every bit: 11111010
Add 1: 11111011
FeatureUnsignedSigned (two's complement)
8-bit range0 to 255−128 to 127
16-bit range0 to 65,535−32,768 to 32,767
32-bit range0 to 4,294,967,295−2,147,483,648 to 2,147,483,647
Leading bitJust another value bitSign bit: 1 means negative
Used forCounts, sizes, addressesOrdinary integers in most languages

Two's complement is used because addition and subtraction work identically for positive and negative values — the same circuitry handles both, with no special case for the sign.

Binary, Decimal, Hex and Octal

DecimalBinaryHexOctal
0000000
1000111
2001022
4010044
81000810
101010A12
151111F17
16100001020
321000002040
64100000040100
1281000000080200
25511111111FF377

Hexadecimal is popular with programmers because one hex digit is exactly four bits, so a byte is always two hex characters. Octal maps to three bits and survives mainly in Unix file permissions, where 755 means rwxr-xr-x.

Powers of Two

PowerValueMeaning
2⁴16One hex digit's range
2⁸256Values in one byte
2¹⁰1,024One kibibyte
2¹⁶65,53616-bit range, TCP port count
2²⁰1,048,576One mebibyte
2³²4,294,967,29632-bit range, IPv4 addresses
2⁵³9,007,199,254,740,992Largest exact integer in a JavaScript number
2⁶⁴18,446,744,073,709,551,61664-bit range

Binary and Text: ASCII

Characters are stored as numbers. In ASCII, each character has a code from 0 to 127 that fits in seven bits, usually stored in a byte.

CharacterDecimalBinary (8-bit)Hex
A650100000141
B660100001042
Z90010110105A
a970110000161
z122011110107A
0480011000030
9570011100139
space320010000020

Notice that uppercase and lowercase differ by exactly 32, which is a single bit. Flipping bit 5 switches the case of any ASCII letter — a trick still used in low-level code.

Binary Overflow

A fixed-width value has a maximum. Add one past it and the result wraps around to zero — the carry has nowhere to go. This is overflow, and it is a real source of software bugs rather than a curiosity.

8-bit unsigned overflow

11111111 (255) + 1
Every column carries, and the final carry falls off the end
= 00000000 (0) — the value wrapped around

8-bit signed overflow

01111111 (127) + 1
= 10000000, which as a signed value is −128
Adding 1 to the largest positive number produced the most negative one
WidthUnsigned maxSigned rangemax + 1 becomes
8-bit255−128 to 1270
16-bit65,535−32,768 to 32,7670
32-bit4,294,967,295−2,147,483,648 to 2,147,483,6470
64-bit18,446,744,073,709,551,615±9.22 × 10¹⁸0

Carry-out versus overflow. They are different signals. Carry-out means the unsigned result did not fit, and is the carry leaving the top bit. Overflow means the signed result is wrong, detected when two numbers of the same sign produce a result of the opposite sign. Processors set separate flags for each, because a program working in unsigned arithmetic cares about one and a program using signed arithmetic cares about the other.

Use the Programmer mode panel in the results above to see any value wrapped to 8, 16, 32 or 64 bits, with an overflow warning when it does not fit.

Binary Memory Units

Because memory is addressed in binary, capacities grow in powers of two rather than powers of ten. That is why 1 KiB is 1,024 bytes and not 1,000.

UnitPowerBytesSI counterpart
1 bita single 0 or 1
1 nibble4 bitsone hex digit
1 byte8 bits
1 KiB (kibibyte)2¹⁰1,0241 kB = 1,000
1 MiB (mebibyte)2²⁰1,048,5761 MB = 1,000,000
1 GiB (gibibyte)2³⁰1,073,741,8241 GB = 1,000,000,000
1 TiB (tebibyte)2⁴⁰1,099,511,627,7761 TB = 10¹²

This is why a drive sold as 1 TB shows as roughly 931 GiB in an operating system. Nothing is missing — the manufacturer counted in powers of ten and the computer counts in powers of two. The difference reaches about 10% by the terabyte scale.

Beyond ASCII: Unicode

ASCII covers 128 characters, which is enough for unaccented English and not much else. Unicode assigns a number, called a code point, to every character in every writing system. UTF-8 then encodes that code point as one to four bytes, staying backward compatible with ASCII.

CharacterCode pointDecimalUTF-8 bytes (binary)Bytes
AU+004165010000011
úU+00FA25011000011 101110102
ا (Arabic alef)U+0627157511011000 101001112
U+20AC836411100010 10000010 101011003
U+4E2D2001311100100 10111000 101011013
😀U+1F60012851211110000 10011111 10011000 100000004

Notice the leading bits. A single-byte character always starts with 0, which is exactly ASCII. Multi-byte sequences start with 110, 1110 or 11110 to announce their length, and every continuation byte starts with 10. That self-describing structure is why a decoder can always find character boundaries, even starting mid-stream.

It also explains why an emoji "counts as" more than one character in some programs: 😀 is a single code point but four bytes in UTF-8, and two units in UTF-16.

Binary and Decimal Fractions: IEEE 754

Binary represents whole numbers exactly, but fractions are another matter. A binary fraction can only represent values whose denominator is a power of two — a half, a quarter, an eighth. One tenth is not among them.

0.1 in binary = 0.0001100110011001100… repeating forever

Just as one third is 0.333… and never terminates in decimal, one tenth never terminates in binary. Since a computer has finite space, it stores the closest value it can. That is why 0.1 + 0.2 gives 0.30000000000000004 in almost every programming language — the inputs were already slightly off before the addition began.

IEEE 754 is the standard that defines this. A 64-bit double stores a sign bit, an 11-bit exponent and a 52-bit fraction — essentially scientific notation in binary. It gives about 15 to 17 significant decimal digits.

FormatTotal bitsSignExponentFractionDecimal digits
Half (float16)161510~3
Single (float32)321823~7
Double (float64)6411152~15–17

This is why financial software stores money in whole cents rather than fractional dollars, and why comparing two floating-point values for exact equality is unreliable. For exact work, use integers or a decimal type — our Big Number Calculator uses exact integer arithmetic and the Decimal Calculator uses exact decimal arithmetic.

Where Binary Is Used

Programming

Bit flags pack many true/false settings into a single integer, checked with AND.

flags & READ_ONLY

Cybersecurity

XOR appears in ciphers, hashing and checksums because it is reversible.

cipher = data ^ key

Networking

Subnet masks are binary AND operations on IP addresses.

IP & 255.255.255.0

Machine Learning

Quantised models store weights in 8-bit or even 1-bit form to save memory.

int8 quantisation

Embedded Systems

Hardware registers are read and written one bit at a time.

PORTB |= (1 << 3)

Databases

Bitmap indexes answer set queries with fast bitwise operations.

bitmap AND bitmap

Graphics

Colours pack red, green, blue and alpha into one 32-bit value.

0xFF00FF00

Digital Electronics

Logic gates are the physical implementation of AND, OR, XOR and NOT.

AND, OR, NAND

Common Mistakes

Watch out for these:
  • Reading binary as decimal. 10 in binary is 2, not ten.
  • Forgetting to carry at 2. In binary 1 + 1 = 10, not 2.
  • Applying NOT without a bit width. The answer differs between 8-bit and 32-bit, so the width must be stated.
  • Confusing logical and bitwise operators. In most languages && is logical while & is bitwise, and they behave differently.
  • Assuming a right shift is always division. For negative numbers in two's complement it rounds toward negative infinity, not toward zero.
  • Mixing up 1000 and 1024. A kilobyte is 1000 bytes under SI, but 2¹⁰ = 1024 is a kibibyte.
  • Trusting a tool that trims bad input. If 1012 returns an answer instead of an error, the tool has silently discarded part of your number.

Practice Questions

Beginner (with answers)

  1. Convert 1010 to decimal.
  2. Convert 20 to binary.
  3. Add 101 + 011.
  4. What is 1111 in hexadecimal?
  5. How many values fit in one byte?
Show answers

1) 10   2) 10100   3) 1000   4) F   5) 256

Advanced (with answers)

  1. Calculate 1100 XOR 1010.
  2. Calculate 1011 × 110.
  3. What is −8 in 8-bit two's complement?
  4. What is 1101 left-shifted by 3?
  5. Convert 11010110 to hexadecimal.
Show answers

1) 0110   2) 1000010 (66)   3) 11111000   4) 1101000   5) D6

Did you know? Gottfried Leibniz described modern binary arithmetic in 1703, more than two centuries before electronic computers existed. He saw a philosophical elegance in representing everything with 1 and 0, and noted that the Chinese I Ching hexagrams encoded the same structure.
Pro tip. To read binary quickly, memorise the powers of two up to 128 and add the positions where a 1 appears. 10110 is 16 + 4 + 2 = 22.
Pro tip. To convert binary to hex, group the bits into fours from the right, padding with leading zeros. Each group becomes one hex digit, so no long division is needed.

🔑 Key Takeaways

  • Binary is base 2, and each place is worth twice the one to its right
  • 8 bits make a byte, holding 256 possible values
  • Binary addition carries at 2, exactly as decimal carries at 10
  • NOT and negative numbers only make sense with a stated bit width
  • Four bits map to one hex digit, three bits to one octal digit

Frequently Asked Questions

What is binary?

Binary is the base 2 number system, using only the digits 0 and 1. Each position is worth twice the one to its right, so 1101 means 8 plus 4 plus 1, which is 13.

Why do computers use binary?

A transistor is reliably either on or off, so two states are easy to detect without error. Binary also matches Boolean logic directly, which is what makes logic gates work.

How do you convert binary to decimal?

Add up the place values wherever a 1 appears. In 1101 those are 8, 4 and 1, giving 13.

How do you convert decimal to binary?

Divide by 2 repeatedly and record each remainder, then read the remainders from bottom to top. Dividing 13 gives remainders 1, 0, 1, 1, so the answer is 1101.

How do you convert binary to hexadecimal?

Group the bits into fours starting from the right, padding with leading zeros, then convert each group to a single hex digit. So 11111111 becomes 1111 1111, which is FF.

How do you convert binary to octal?

Group the bits into threes from the right and convert each group. So 11111111 becomes 011 111 111, which is 377 in octal.

How do you add binary numbers?

Add column by column as in decimal, but carry when the total reaches 2 rather than 10. So 1 plus 1 is 10, meaning zero with a carry of one.

How do you multiply binary numbers?

Use long multiplication. Each partial product is either a copy of the first number shifted left, or all zeros, which makes it simpler than decimal multiplication.

What is a bit?

A bit is a single binary digit, either 0 or 1. It is the smallest unit of information a computer stores.

What is a byte?

A byte is eight bits, which can represent 256 different values from 0 to 255. It is the usual unit for measuring memory and file size.

What is bitwise AND?

Bitwise AND compares two numbers bit by bit and gives 1 only where both bits are 1. It is mainly used for masking, which keeps some bits and clears others.

What is bitwise OR?

Bitwise OR gives 1 wherever either bit is 1. It is commonly used to set flags without disturbing the other bits.

What is XOR?

XOR, or exclusive or, gives 1 only where the two bits differ. Applying it twice with the same value returns the original, which makes it useful in ciphers and checksums.

What is bitwise NOT?

Bitwise NOT flips every bit. The result depends on the bit width, because leading zeros also flip, so NOT of 00001010 in 8 bits is 11110101.

What do binary shifts do?

A left shift moves every bit one place left, doubling the value for each place. A right shift moves bits right, halving the value and discarding what falls off the end.

What is two's complement?

Two's complement is how computers store negative numbers. Invert every bit of the positive value and add 1, so minus 5 in 8 bits becomes 11111011.

What is the difference between signed and unsigned binary?

Unsigned treats every bit as value, so 8 bits cover 0 to 255. Signed uses the leading bit as a sign, so 8 bits cover minus 128 to 127.

Why is hexadecimal used with binary?

One hex digit is exactly four bits, so any byte is two hex characters. That makes hex a compact and reliable shorthand for binary values.

How is binary used in programming?

Programmers use bit flags to pack many settings into one integer, masks to extract fields, and shifts for fast multiplication or division by powers of two.

How is binary used in networking?

Subnet masks are applied to IP addresses with a bitwise AND to work out which network an address belongs to, which is why masks are written as runs of ones followed by zeros.

How is binary used in AI?

Large models are often quantised so weights are stored in 8-bit or even 1-bit form. This cuts memory and speeds up inference at a small cost in accuracy.

Is this Binary Calculator free?

Yes. It is free with no sign-up, works on any device, and runs entirely in your browser so your entries stay private.

References

Last updated: July 2026
Reviewed by Mohsin Iqbal. All arithmetic and bitwise operations use arbitrary-precision integers, so results stay exact well beyond the 32-bit and 53-bit limits that affect many browser-based binary tools. Input is validated character by character and rejected if it contains a non-binary digit, rather than being silently truncated. Operations that depend on word size, such as NOT and negative values, require you to choose a bit width. This page is for educational purposes.