AJ Designer

Binary Calculator

Try a quick example:

42 (decimal) =

101010₂

Solution Details

Show your work
  1. 42 (base 10) = 101010 (base 2)
  2. Hex: 2a Octal: 52 Bits: 6
  3. Final answer: 101010₂
Other representations
Decimal (base 10):
42
Hex (base 16):
0x2a
Octal (base 8):
52
Bit length:
6 bits
Share:

Decimal to Binary

Convert a non-negative integer in base 10 to its binary (base 2) representation. Repeatedly divide by 2 and read the remainders bottom-up to get the bit pattern.

decimal n → binary by repeated division by 2

Binary to Decimal

Convert a binary number to base 10 by multiplying each bit by its place value (a power of 2) and adding the results.

binary b → decimal by sum of bit × 2ⁿ

Binary Addition

Add two binary numbers digit by digit from right to left, carrying a 1 to the next column whenever the column sum reaches 2.

a + b (base 2, with carries)

Binary Subtraction

Subtract two binary numbers digit by digit from right to left, borrowing from the next column whenever the top bit is smaller than the bottom bit.

a − b (base 2, with borrows)

Binary Multiplication

Multiply two binary numbers using the shift-and-add algorithm: for each 1 bit in the multiplier, add a shifted copy of the multiplicand.

a × b (shift-and-add)

Binary Division

Integer-divide two binary numbers and return both the quotient and the remainder. Uses repeated subtraction (or shift-and-subtract) the way long division does in base 10.

a ÷ b → quotient and remainder

How It Works

Binary is a positional number system in base 2 — it uses only the digits 0 and 1. Every position represents a power of two, increasing from right to left: the rightmost digit is the ones place (2⁰), then twos (2¹), fours (2²), eights (2³), and so on. To convert a decimal number to binary, divide by 2 repeatedly and read the remainders from bottom to top. To convert binary to decimal, multiply each bit by its place value and add. Binary arithmetic (add, subtract, multiply, divide) follows the same column rules as base-10 arithmetic, except carries and borrows happen at 2 instead of at 10.

Example Problem

Convert the decimal number 42 to binary.

  1. Divide 42 by 2: quotient 21, remainder 0. Record the remainder.
  2. Divide 21 by 2: quotient 10, remainder 1. Record the remainder.
  3. Divide 10 by 2: quotient 5, remainder 0. Record the remainder.
  4. Divide 5 by 2: quotient 2, remainder 1. Record the remainder.
  5. Divide 2 by 2: quotient 1, remainder 0. Record the remainder.
  6. Divide 1 by 2: quotient 0, remainder 1. Stop when the quotient reaches 0.
  7. Read the remainders bottom-up: 1, 0, 1, 0, 1, 0. That gives 101010 in binary.
  8. Verify by expanding the place values: 32 + 8 + 2 = 42. ✓

Therefore, 42 (decimal) = 101010 (binary).

Key Concepts

A bit is a single binary digit, 0 or 1. Four bits make a nibble (16 possible values, 0–15, used to represent one hexadecimal digit). Eight bits make a byte, the standard unit of memory addressing — one byte can hold 256 different values (0 to 255 unsigned, or −128 to 127 signed). Larger groups have names too: 16 bits = word (on most architectures), 32 bits = double word, 64 bits = quad word. To represent negative numbers in a fixed bit width, computers use two's complement: invert every bit and add 1. Two's complement makes signed addition and subtraction use the exact same circuitry as unsigned arithmetic — a major reason it became the standard.

Applications

  • Programming: bitwise operators (AND, OR, XOR, shifts), bit flags, and storage layout all rely on understanding binary
  • Networking: IPv4 addresses and subnet masks are 32-bit binary numbers; CIDR notation like /24 specifies how many leading bits are the network portion
  • Embedded systems: microcontroller registers expose individual hardware bits, so reading and writing peripherals requires binary literacy
  • Error detection and correction: parity bits, checksums, Hamming codes, and CRCs all work by manipulating binary digits to detect or repair transmission errors
  • Cryptography: stream ciphers and block ciphers operate on binary data; key sizes are quoted in bits because that determines brute-force difficulty

Common Mistakes

  • Mixing up 0 (zero) and O (the letter), or 1 (one) and l (lowercase L) — binary uses only the digit forms 0 and 1, never letters
  • Reading binary from left to right when looking at place values — bits are written left-to-right (MSB first) but place values increase right-to-left (the rightmost bit is 2⁰)
  • Assuming every binary number must fit in 8 bits — natural integers in binary have no fixed width; padding to a byte (or 16/32/64 bits) is only needed when storing in a typed memory location
  • Forgetting carries in addition — when a column sums to 2, write 0 and carry 1 (just like carrying 1 when a base-10 column sums to 10)
  • Confusing binary with two's complement — plain binary represents non-negative integers; two's complement is a specific signed-integer encoding that requires a fixed bit width

Frequently Asked Questions

How do you convert decimal to binary?

Divide the decimal number by 2 repeatedly, recording the remainder (0 or 1) at each step. When the quotient reaches 0, stop. Read the remainders from bottom to top — that sequence is the binary representation. For example, 42 ÷ 2 gives remainders 0, 1, 0, 1, 0, 1 from bottom to top, so 42 in binary is 101010.

How do you convert binary to decimal?

Multiply each bit by its place value (a power of 2) and add the results. The rightmost bit is 2⁰ = 1, the next is 2¹ = 2, then 2² = 4, 2³ = 8, and so on. For example, 10110101 = 128 + 32 + 16 + 4 + 1 = 181.

How do you add binary numbers?

Align the numbers by their rightmost bit and add column by column. The rules per column are 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 = 0 with a carry of 1 to the next column. For example, 101 + 011 = 1000 (5 + 3 = 8).

What is binary?

Binary is the base-2 number system. It uses only two digits, 0 and 1, instead of the ten digits of decimal. Each position in a binary number represents a power of 2, so the rightmost digit is the ones place, then twos, fours, eights, and so on doubling at each step.

Why do computers use binary?

Digital circuits are built from switches that are either on or off, which maps directly to the two digits of binary. Representing data with only two voltage levels (high and low) is far more reliable than trying to distinguish ten or more levels in the presence of electrical noise. Binary also makes arithmetic circuits much simpler: a binary full-adder has only a handful of logic gates.

How do you read a binary number?

Read the bits left to right just as you would any number, but remember that the place values increase right to left in powers of 2. The leftmost bit is the most significant (largest place value) and the rightmost bit is the least significant (the ones place). You don't pronounce each bit individually — for example, you'd say '1 0 1 0 1 0' or call it 'one-oh-one-oh-one-oh in binary' rather than reading it as 'one hundred and one thousand ten'.

What is a byte?

A byte is 8 bits, the standard unit of memory addressing on essentially every modern computer. An 8-bit byte can hold one of 256 distinct values (0 to 255 unsigned, or −128 to 127 in two's-complement signed form). A nibble is half a byte (4 bits, 16 values, one hexadecimal digit).

How do you handle negative numbers in binary?

In a fixed-width signed integer, computers use two's-complement encoding: to negate a value, flip every bit and add 1. With this scheme, addition and subtraction use the same circuitry for signed and unsigned values. This calculator shows negative subtraction results with a plain '-' sign prefix rather than encoding them in two's complement, because that encoding only makes sense with a chosen bit width.

Reference: Standard positional base-2 numeral system and binary arithmetic algorithms; two's complement and IEEE byte-width conventions from Patterson & Hennessy, Computer Organization and Design.

Binary Place Values

Every position in a binary number has a weight that is a power of two, increasing right to left. To convert a binary number to decimal, multiply each bit by its place value and add the results:

n = bk·2k + bk-1·2k-1 + … + b1·2 + b0·1

Where:

  • bi is the bit at position i (either 0 or 1)
  • 2i is the place value at position i — the rightmost bit is 2⁰ = 1
  • k is the index of the most significant (leftmost) bit

For example, 10110101 = 128 + 32 + 16 + 4 + 1 = 181. Every binary number expands this way, which is why an 8-bit number can represent any value from 0 to 255 (one byte).

Place Value Diagram

Place-value ladder for an 8-bit example. Each column is a power of two, with weights doubling right to left. Setting bits 7, 5, 3, and 1 gives 128 + 32 + 8 + 2 = 170.

Binary place values for an 8-bit number22222³2²2¹2128643216842110101010128 + 32 + 8 + 2= 170 (decimal)

8-bit place-value ladder. Each bit is multiplied by its place weight (a power of 2) and the products are summed to give the decimal value.

Worked Examples

Decimal to Binary

Convert 42 to binary

  • Divide repeatedly by 2 and record each remainder
  • 42 ÷ 2 = 21 r 0
  • 21 ÷ 2 = 10 r 1
  • 10 ÷ 2 = 5 r 0
  • 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1
  • Read remainders bottom-up: 101010

42 = 101010₂

Binary to Decimal

Convert 10110101 to decimal

  • Write place values: 128, 64, 32, 16, 8, 4, 2, 1
  • Multiply each bit by its weight: 1·128, 0·64, 1·32, 1·16, 0·8, 1·4, 0·2, 1·1
  • Sum the non-zero terms: 128 + 32 + 16 + 4 + 1
  • = 181

10110101₂ = 181

Binary Addition

Add 101 + 011 in binary

  • Align by the rightmost bit
  • Column 0: 1 + 1 = 10 → write 0, carry 1
  • Column 1: 0 + 1 + 1 (carry) = 10 → write 0, carry 1
  • Column 2: 1 + 0 + 1 (carry) = 10 → write 0, carry 1
  • Column 3: 0 + 0 + 1 (carry) = 1 → write 1
  • Result: 1000 (which is 8 in decimal — verify: 5 + 3 = 8 ✓)

101 + 011 = 1000₂

Related Calculators

Related Sites