Binary arithmetic, bitwise operations and conversions between binary, decimal, hexadecimal and octal — with exact results at any size.
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 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
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.
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.
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.
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Power of two | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
| Decimal value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Example: 1101 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
To read a binary number, add up the place values wherever there is a 1. For 1101 that is 8 + 4 + 1 = 13.
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.
| Operation | Rule | 1100 op 1010 | Typical use |
|---|---|---|---|
| AND (&) | 1 only if both bits are 1 | 1000 | Masking — keeping selected bits |
| OR (|) | 1 if either bit is 1 | 1110 | Setting flags |
| XOR (^) | 1 if the bits differ | 0110 | Toggling bits, checksums, simple ciphers |
| NOT (~) | Flips every bit | depends on bit width | Inverting a mask |
| Left shift (<<) | Moves bits left, multiplying by 2 each place | 1100 << 1 = 11000 | Fast multiplication |
| Right shift (>>) | Moves bits right, dividing by 2 each place | 1100 >> 1 = 110 | Fast 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.
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.
| Feature | Unsigned | Signed (two's complement) |
|---|---|---|
| 8-bit range | 0 to 255 | −128 to 127 |
| 16-bit range | 0 to 65,535 | −32,768 to 32,767 |
| 32-bit range | 0 to 4,294,967,295 | −2,147,483,648 to 2,147,483,647 |
| Leading bit | Just another value bit | Sign bit: 1 means negative |
| Used for | Counts, sizes, addresses | Ordinary 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.
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 4 | 0100 | 4 | 4 |
| 8 | 1000 | 8 | 10 |
| 10 | 1010 | A | 12 |
| 15 | 1111 | F | 17 |
| 16 | 10000 | 10 | 20 |
| 32 | 100000 | 20 | 40 |
| 64 | 1000000 | 40 | 100 |
| 128 | 10000000 | 80 | 200 |
| 255 | 11111111 | FF | 377 |
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.
| Power | Value | Meaning |
|---|---|---|
| 2⁴ | 16 | One hex digit's range |
| 2⁸ | 256 | Values in one byte |
| 2¹⁰ | 1,024 | One kibibyte |
| 2¹⁶ | 65,536 | 16-bit range, TCP port count |
| 2²⁰ | 1,048,576 | One mebibyte |
| 2³² | 4,294,967,296 | 32-bit range, IPv4 addresses |
| 2⁵³ | 9,007,199,254,740,992 | Largest exact integer in a JavaScript number |
| 2⁶⁴ | 18,446,744,073,709,551,616 | 64-bit range |
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.
| Character | Decimal | Binary (8-bit) | Hex |
|---|---|---|---|
| A | 65 | 01000001 | 41 |
| B | 66 | 01000010 | 42 |
| Z | 90 | 01011010 | 5A |
| a | 97 | 01100001 | 61 |
| z | 122 | 01111010 | 7A |
| 0 | 48 | 00110000 | 30 |
| 9 | 57 | 00111001 | 39 |
| space | 32 | 00100000 | 20 |
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.
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.
| Width | Unsigned max | Signed range | max + 1 becomes |
|---|---|---|---|
| 8-bit | 255 | −128 to 127 | 0 |
| 16-bit | 65,535 | −32,768 to 32,767 | 0 |
| 32-bit | 4,294,967,295 | −2,147,483,648 to 2,147,483,647 | 0 |
| 64-bit | 18,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.
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.
| Unit | Power | Bytes | SI counterpart |
|---|---|---|---|
| 1 bit | — | a single 0 or 1 | — |
| 1 nibble | — | 4 bits | one hex digit |
| 1 byte | 2³ | 8 bits | — |
| 1 KiB (kibibyte) | 2¹⁰ | 1,024 | 1 kB = 1,000 |
| 1 MiB (mebibyte) | 2²⁰ | 1,048,576 | 1 MB = 1,000,000 |
| 1 GiB (gibibyte) | 2³⁰ | 1,073,741,824 | 1 GB = 1,000,000,000 |
| 1 TiB (tebibyte) | 2⁴⁰ | 1,099,511,627,776 | 1 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.
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.
| Character | Code point | Decimal | UTF-8 bytes (binary) | Bytes |
|---|---|---|---|---|
| A | U+0041 | 65 | 01000001 | 1 |
| ú | U+00FA | 250 | 11000011 10111010 | 2 |
| ا (Arabic alef) | U+0627 | 1575 | 11011000 10100111 | 2 |
| € | U+20AC | 8364 | 11100010 10000010 10101100 | 3 |
| 中 | U+4E2D | 20013 | 11100100 10111000 10101101 | 3 |
| 😀 | U+1F600 | 128512 | 11110000 10011111 10011000 10000000 | 4 |
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 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.
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.
| Format | Total bits | Sign | Exponent | Fraction | Decimal digits |
|---|---|---|---|---|---|
| Half (float16) | 16 | 1 | 5 | 10 | ~3 |
| Single (float32) | 32 | 1 | 8 | 23 | ~7 |
| Double (float64) | 64 | 1 | 11 | 52 | ~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.
Bit flags pack many true/false settings into a single integer, checked with AND.
flags & READ_ONLYXOR appears in ciphers, hashing and checksums because it is reversible.
cipher = data ^ keySubnet masks are binary AND operations on IP addresses.
IP & 255.255.255.0Quantised models store weights in 8-bit or even 1-bit form to save memory.
int8 quantisationHardware registers are read and written one bit at a time.
PORTB |= (1 << 3)Bitmap indexes answer set queries with fast bitwise operations.
bitmap AND bitmapColours pack red, green, blue and alpha into one 32-bit value.
0xFF00FF00Logic gates are the physical implementation of AND, OR, XOR and NOT.
AND, OR, NAND1) 10 2) 10100 3) 1000 4) F 5) 256
1) 0110 2) 1000010 (66) 3) 11111000 4) 1101000 5) D6
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.