Binary Calculator

Convert between binary, decimal, hexadecimal, and octal. Perform binary arithmetic including AND, OR, XOR.

Number Base Converter

Decimal

42

Binary

101010

Hexadecimal

2A

Octal

52

Binary Arithmetic

Result (Binary)

10

Result (Decimal)

2

How to Use the Binary Calculator

This binary calculator is two tools in one: a number base converter that handles decimal, binary, hex, and octal, plus a binary math calculator for AND, OR, XOR, NOT, bit shifts, addition, and subtraction. Every result updates the moment you change an input, so you can use it as a binary to decimal calculator, a decimal to binary calculator, or a binary addition calculator without switching modes.

  1. Pick your starting base. In the Number Base Converter, click Decimal, Binary, Hexadecimal, or Octal. The tab you choose tells the converter how to read the digits you are about to type.
  2. Type the number. Enter 42 in decimal, 101010 in binary, 2A in hex, or 52 in octal. The converter rejects invalid digits (a 2 in binary, an 8 in octal, a G in hex) and shows an error instead of a wrong answer.
  3. Read the four outputs. Decimal, binary, hex, and octal forms of the same value appear in the result grid. Use these side by side to learn how to convert binary to decimal in your head or to sanity-check a value from a programming task.
  4. Switch to Binary Arithmetic when you need to perform math. Type Binary A (for example 1010), pick an operation, and if the operation needs two operands, type Binary B (for example 0110). The result appears in binary and decimal so you can cross-check the answer.
  5. Choose the operation. AND, OR, and XOR compare bits position by position. NOT flips every bit in Binary A. Left Shift and Right Shift move the bits of Binary A one place, multiplying or dividing by 2. ADD and SUBTRACT perform standard binary addition and subtraction.

The binary converter and arithmetic tool share the same page state, so you can copy a result out of one and paste it into the other. A common workflow is to convert a decimal number to binary, run a bitwise operation on it, then paste the binary result back into the converter to see the decimal and hex equivalents.

Binary Math: Conversion Formulas and Arithmetic Rules

Binary is base 2: every digit is either 0 or 1, and each position is worth twice the position to its right. The formulas below cover how to convert binary to decimal, how to convert decimal to binary, and every operation the binary math calculator above supports.

Binary to Decimal: Multiply Each Bit by Its Power of 2

To convert a binary number to decimal, multiply every bit by 2 raised to its position (counting from 0 on the right), then add the results for the bits that are 1. Positions with a 0 contribute nothing and can be skipped.

Binary:    1  0  1  1  0
Position:  4  3  2  1  0
Value:    16  8  4  2  1

10110₂ = (1×16) + (0×8) + (1×4) + (1×2) + (0×1)
       = 16 + 4 + 2
       = 22₁₀

The same method scales to any width. For 11111111₂, add 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, the largest value an 8-bit byte can hold.

Decimal to Binary: Divide by 2, Read Remainders Bottom Up

Divide the decimal number by 2. Write down the remainder (0 or 1). Divide the quotient by 2 again, write down the next remainder, and repeat until the quotient is 0. Then read the remainders from bottom to top.

Convert 45 to binary:
45 ÷ 2 = 22 remainder 1   ← lowest bit
22 ÷ 2 = 11 remainder 0
11 ÷ 2 =  5 remainder 1
 5 ÷ 2 =  2 remainder 1
 2 ÷ 2 =  1 remainder 0
 1 ÷ 2 =  0 remainder 1   ← highest bit

Reading bottom up: 101101₂
Check: 32 + 8 + 4 + 1 = 45 ✓

Binary Addition, Subtraction, and Multiplication

Binary arithmetic works exactly like grade-school decimal arithmetic, except that you only have two digits and carrying happens every time you reach 2 instead of 10.

Addition rules:
  0 + 0 = 0
  0 + 1 = 1
  1 + 1 = 10 (write 0, carry 1)
  1 + 1 + 1 = 11 (write 1, carry 1)

Example: 1011 + 0110
   1 1
   1 0 1 1   (11)
 + 0 1 1 0    (6)
 ─────────
  1 0 0 0 1  (17) ✓
Subtraction: borrow 1 from the next column (worth 2).

Example: 1100 − 0101
  1 1 0 0   (12)
 −0 1 0 1    (5)
 ─────────
  0 1 1 1    (7) ✓
Multiplication: shift and add, just like long multiplication.

Example: 101 × 11  (5 × 3)
     1 0 1
  ×    1 1
  ─────────
     1 0 1   (101 × 1)
   1 0 1     (101 × 1, shifted)
  ─────────
   1 1 1 1   = 15 ✓

Bitwise Operations: AND, OR, XOR, NOT, Shifts

AND:   1 AND 1 = 1, anything AND 0 = 0
OR:    0 OR 0 = 0, anything OR 1 = 1
XOR:   same bits = 0, different bits = 1
NOT:   flips all bits (0→1, 1→0)
Left Shift:  multiply by 2 (append 0 on right)
Right Shift: integer divide by 2 (remove last bit)

Example: 1010 (10) AND 0110 (6)
  1010
& 0110
------
  0010  = 2 decimal

Binary addition:
  0 + 0 = 0
  0 + 1 = 1
  1 + 1 = 10 (carry the 1)
  1 + 1 + 1 = 11

Two's Complement: How Negative Numbers Are Stored

Computers store negative numbers using two's complement. To negate a binary number, flip every bit (0 becomes 1, 1 becomes 0) and add 1 to the result. The leftmost bit then acts as a sign: 0 for positive, 1 for negative.

Express −5 in 8-bit two's complement:
 +5 =  0000 0101
 flip:  1111 1010
 +1:    1111 1011   = −5

Check: 1111 1011 + 0000 0101
     = 1 0000 0000 (9 bits), drop the overflow bit
     = 0000 0000 = 0 ✓

An 8-bit signed integer holds values from −128 (10000000₂) to +127 (01111111₂). A 16-bit signed integer ranges from −32,768 to +32,767. A 32-bit signed integer ranges from roughly −2.15 billion to +2.15 billion. Unsigned integers of the same width double the positive range because they use the sign bit for magnitude.

Quick Reference: Decimal, Binary, Hex, Octal

Each hexadecimal digit maps to exactly 4 binary bits, which is why programmers write memory addresses and color codes in hex. Octal groups bits three at a time and still appears in Unix file permissions.

DecimalBinaryHexOctal
0000
1111
711177
81000810
151111F17
16100001020
64100000040100
100110010064144
12711111117F177
25511111111FF377

Binary in the Real World: Bits, Bytes, and Where Base 2 Shows Up

Binary is not a historical curiosity. It runs every computer, phone, router, and microcontroller on the planet. Knowing how bits and bytes combine into the numbers you see in code, IP addresses, and file sizes makes debugging and capacity planning much easier. This section connects the binary math calculator above to the systems that use it.

Why Computers Use Binary Instead of Decimal

Every digital circuit is built from transistors that have two reliable states: on and off, high voltage and low voltage, magnetized and not magnetized. These two states map directly to 1 and 0. Building circuits that reliably distinguish ten different voltage levels (for decimal) is far harder and far less tolerant of noise, temperature swings, and manufacturing variance. Binary also plugs directly into Boolean logic (AND, OR, NOT), which is how every CPU instruction, comparison, and conditional jump is ultimately computed. Using base 2 means the physical circuitry and the math are the same thing.

Bits, Bytes, and the Powers of 2 You Should Know

A bit is a single binary digit, holding either 0 or 1. A byte is 8 bits, which can represent 2⁸ = 256 different values (0 to 255 unsigned, or −128 to 127 signed). A kilobyte is 1,024 bytes in binary units (2¹⁰), not 1,000. The binary units (KiB, MiB, GiB) are the powers of 2 most software uses internally, while storage vendors often advertise in decimal units (1 GB = 1,000,000,000 bytes). That gap is why a "1 TB" drive shows up in Windows as roughly 931 GiB.

UnitPower of 2BytesCommon Use
1 byte2⁸ values1one ASCII character
1 KiB2¹⁰1,024small text file
1 MiB2²⁰1,048,576one-minute MP3
1 GiB2³⁰1,073,741,824HD video, RAM stick
1 TiB2⁴⁰1,099,511,627,776hard drive capacity

Integer Ranges by Bit Width

When you see data types like int32, uint16, or long in code, the number is the bit width and the prefix tells you whether it is signed or unsigned. These ranges are fixed by the math and come up constantly in API limits, database schemas, and overflow bugs.

WidthUnsigned RangeSigned RangeTypical Use
8-bit0 to 255−128 to 127a byte, color channel
16-bit0 to 65,535−32,768 to 32,767small IDs, port numbers
32-bit0 to 4,294,967,295−2,147,483,648 to 2,147,483,647most integer IDs, IPv4
64-bit0 to ~1.8×10¹⁹±9.2×10¹⁸timestamps, large counts

The classic Y2K38 bug is a 32-bit signed integer overflow: Unix time (seconds since 1970) hits the maximum 32-bit signed value on January 19, 2038, and wraps around to a negative number. Moving to 64-bit timestamps pushes the problem roughly 292 billion years into the future.

Where You Actually See Binary Day to Day

Binary math is not just for compiler writers. A few everyday places where it shows up:

  • IPv4 addresses and subnet masks: 192.168.1.1 is four 8-bit numbers written in decimal. The subnet mask 255.255.255.0 is 11111111.11111111.11111111.00000000 in binary, and the /24 CIDR notation just counts the leading 1 bits.
  • Unix file permissions (chmod): chmod 755 sets rwx (111 = 7) for the owner, r-x (101 = 5) for the group, and r-x (101 = 5) for everyone else. Each digit is a 3-bit binary number for read, write, execute.
  • Bitmask flags: APIs often pack many boolean options into a single integer where each bit is one flag. flags = READ | WRITE | EXECUTE is a binary OR, and if (flags & WRITE) is a binary AND used to test one bit.
  • Color codes: #FF5733 is three hex bytes for red, green, blue. FF in binary is 11111111 = 255, the maximum intensity of one color channel.
  • Network ports, MAC addresses, UUIDs, hashes: all stored as raw bits and displayed in hex or decimal for readability.

Frequently Asked Questions

Divide the number by 2 repeatedly, noting the remainder each time, until the quotient is 0. Read the remainders from bottom to top. For 42: 42÷2=21 r0, 21÷2=10 r1, 10÷2=5 r0, 5÷2=2 r1, 2÷2=1 r0, 1÷2=0 r1. Read remainders upward: 101010. So 42 in decimal = 101010 in binary.

Related Calculators