Mathematics

How to Convert Between Binary and Decimal

Binary to decimal is place value — multiply each binary digit by its power-of-2 position and add them up; decimal to binary is repeated division by 2, reading the remainders from bottom to top.

Binary to decimal: place value

Each position in a binary number is worth a power of 2, doubling from right to left: 1, 2, 4, 8, 16, and so on. To convert, multiply each digit by its place value and add the results. For 11111111 (eight 1s): 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. For the shorter 1011: 1×8 + 0×4 + 1×2 + 1×1 = 8 + 0 + 2 + 1 = 11.

Decimal to binary: repeated division by 2

Going the other way, divide the decimal number by 2 repeatedly, writing down each remainder, until the number reaches 0 — then read the remainders from bottom to top. For 255: 255÷2=127 r1, 127÷2=63 r1, 63÷2=31 r1, 31÷2=15 r1, 15÷2=7 r1, 7÷2=3 r1, 3÷2=1 r1, 1÷2=0 r1 — eight remainders, all 1, read bottom-to-top gives 11111111, matching the first example exactly.

A shorter example, decimal 100

100÷2=50 r0, 50÷2=25 r0, 25÷2=12 r1, 12÷2=6 r0, 6÷2=3 r0, 3÷2=1 r1, 1÷2=0 r1. Reading the remainders bottom to top gives 1100100 — seven digits, since 100 needs fewer bits than 255 does.

Why this works

Both directions rely on the same idea: a binary number is a sum of powers of 2, and a decimal number is a sum of powers of 10. Converting binary to decimal directly evaluates that sum of powers of 2. Converting decimal to binary works backwards — the remainder at each division step is exactly the next binary digit, because dividing by 2 repeatedly peels off one power-of-2 place at a time, least-significant digit first.