Formula · computing

Binary to Decimal Formula

Sum each bit times 2 raised to its position.

Quick answer
Formula

D = Σ (bᵢ × 2ⁱ)

How it works

Binary is ordinary positional notation with two digits instead of ten. In decimal, 134 means 1×100 + 3×10 + 4×1, each column being the next power of ten. In binary each column is the next power of two, so 1011 means 1×8 + 0×4 + 1×2 + 1×1 = 11. The counting starts at the right-hand end and at zero: the rightmost bit is 2⁰ = 1, not 2¹. Getting that wrong doubles every answer. Computers use binary because a transistor is reliably either on or off, and distinguishing two voltage levels is far more robust than distinguishing ten. Working the conversion by hand is worth doing once because it explains numbers that appear everywhere in computing. Eight bits hold 2⁸ = 256 distinct values, so an unsigned byte runs 0 to 255 — which is why colour channels stop at 255 and why old sprite limits and item counts so often sat at 255. Sixteen bits reach 65,535, thirty-two bits reach 4,294,967,295, and that last figure is the reason a 32-bit counter of seconds overflows in 2038. It is also why 2¹⁰ = 1,024 keeps appearing where you might expect 1,000, and therefore why a drive sold as one terabyte shows up as roughly 931 GB.

Variables

  • DDecimal value
  • bᵢBit at position i (0 or 1)
  • iPosition counted from the right starting at 0

Worked examples

InputResult
1011₂1·8 + 0·4 + 1·2 + 1·1 = 11
11111111₂= 255 (one byte maxed out)
10000000₂= 128 (highest bit of a byte)

Practical applications

  • Reading bitmasks, permission bits and hardware flags in low-level code
  • Interpreting file formats, network packets and memory dumps by hand
  • Understanding why an unsigned value wraps at 255, 65,535 or 4,294,967,295
  • Working through the binary questions that appear in most computer-science courses and interviews

Common mistakes

  • Counting positions from the left. The exponent is fixed by distance from the right-hand end, so the number of digits does not change what any column is worth.
  • Starting the exponent at 1. The rightmost bit is 2⁰ = 1.
  • Forgetting that leading zeros change nothing. 0001011 and 1011 are both 11.
  • Assuming an eight-bit value can hold 256. It holds 256 distinct values, but the largest is 255, because zero is one of them.

Used in

ProgrammingNetwork engineeringHardware design

Use it in a tool

FAQs

Why is 255 the max for one byte?+

Eight bits, each doubling: 128+64+32+16+8+4+2+1 = 255. Add 1 and you'd need a 9th bit.

How does signed binary work?+

Most systems use two's complement: the highest bit is the sign, so an 8-bit signed int spans −128 to +127.

Explore the topic

Knowledge graph
Related comparisons

Related formulas