TSE.
MathematicsFinanceHealthPhysicsEngineeringBrowse all

Computer Science · Digital & Computing

Binary ↔ Decimal Converter

Convert binary (base-2) to decimal (base-10) and back — bidirectional conversion in both directions.

Calculator

Advertisement

Formula

Binary to decimal: each bit b_i is multiplied by 2 raised to its position i (from right). Decimal to binary: repeatedly divide by 2 and collect remainders.

Source: Knuth, D. E. — The Art of Computer Programming, Vol. 2. Addison-Wesley, 1997.

How it works

Binary to decimal uses positional notation: each bit is multiplied by its corresponding power of 2 (rightmost = 2⁰), and all products are summed. Decimal to binary uses repeated division by 2 — the remainders read bottom-to-top give the binary representation.

For example: binary 1011 = (1×8)+(0×4)+(1×2)+(1×1) = 11 decimal. And decimal 11 → 11÷2=5 r1, 5÷2=2 r1, 2÷2=1 r0, 1÷2=0 r1 → binary 1011.

Worked example

Binary → Decimal: Convert 11010110.
Positions: 1×128 + 1×64 + 0×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 214

Decimal → Binary: Convert 214.
214÷2=107 r0, 107÷2=53 r1, 53÷2=26 r1, 26÷2=13 r0, 13÷2=6 r1, 6÷2=3 r0, 3÷2=1 r1, 1÷2=0 r1 → read remainders upward: 11010110

Limitations & notes

Handles non-negative integers only. Very large numbers (> 53 bits) may lose precision due to JavaScript's floating-point limit. Does not support binary fractions, two's complement signed integers, or binary-coded decimal (BCD).

Frequently asked questions

How do I convert binary to decimal manually?

Write each bit and multiply it by 2 raised to its position (0 from the right). Sum all results. Example: 1101 = 8+4+0+1 = 13.

How do I convert decimal to binary manually?

Repeatedly divide by 2 and record remainders. Read the remainders from bottom to top. Example: 13 → 6r1, 3r0, 1r1, 0r1 → binary 1101.

What is the largest 8-bit binary number?

11111111 in binary = 255 in decimal. An 8-bit number can represent 0 to 255 (2⁸ − 1 = 255).

How does binary relate to hexadecimal?

Every 4 binary digits map to one hex digit. Binary 1010 = hex A = decimal 10. This makes hex a compact way to represent binary values.

What is two's complement?

Two's complement is how CPUs represent negative integers in binary. This converter handles unsigned positive integers only. For signed binary, use a dedicated two's complement calculator.

Last updated: 2025-01-15 · Formula verified against primary sources.