X Xerobit

Binary to Decimal — Convert Binary Numbers the Right Way

Binary to decimal conversion is foundational to understanding how computers store numbers. Here's the math, the algorithm, and how to convert in your head for small values.

Mian Ali Khalid · · 6 min read
Use the tool
Number Base Converter
Convert between binary, octal, decimal, hexadecimal, and text (UTF-8). Handles arbitrary lengths. Per-byte and per-character views.
Open Number Base Converter →

Binary to decimal conversion is the process of reading a base-2 number (ones and zeros) and expressing it in the base-10 system humans use. Binary 1010 equals decimal 10. Binary 11111111 equals decimal 255 — the maximum value of one byte.

Use the Number Base Converter to convert between binary, decimal, hex, and octal instantly.

How binary numbers work

Every digit in a binary number represents a power of 2, starting from 2⁰ on the right:

Position:  7    6    5    4    3    2    1    0
Power:     2⁷   2⁶   2⁵   2⁴   2³   2²   2¹   2⁰
Value:     128  64   32   16   8    4    2    1

Each bit is either 0 (the power doesn’t contribute) or 1 (it does). The decimal value is the sum of all contributing powers.

The conversion algorithm

To convert binary to decimal, multiply each bit by its positional value and sum:

Binary: 1 0 1 1 0 1
        │ │ │ │ │ └── × 2⁰ = × 1 = 1
        │ │ │ │ └──── × 2¹ = × 2 = 0
        │ │ │ └────── × 2² = × 4 = 4
        │ │ └──────── × 2³ = × 8 = 8
        │ └────────── × 2⁴ = × 16 = 0
        └──────────── × 2⁵ = × 32 = 32

Sum = 32 + 0 + 8 + 4 + 0 + 1 = 45

Binary 101101 = decimal 45.

Common binary values to memorize

These appear constantly when working with networking, file permissions, and bit operations:

BinaryDecimalContext
0000 00000Null byte
0000 00011Lowest bit set
0000 111115Low nibble mask
1111 0000240High nibble mask
0111 1111127Max positive int8
1000 0000128Min negative int8
1111 1111255Max uint8 / FF in hex
0001 0000 00002562⁸
1 0000 0000256Same — leading 1 in 9th position

How to convert in code

JavaScript

// Binary string to decimal integer:
const binary = '101101';
const decimal = parseInt(binary, 2);
console.log(decimal); // 45

// Decimal to binary string:
const dec = 45;
const bin = dec.toString(2);
console.log(bin); // "101101"

// Pad to 8 bits:
console.log(dec.toString(2).padStart(8, '0')); // "00101101"

Python

# Binary string to decimal:
binary = '101101'
decimal = int(binary, 2)
print(decimal)  # 45

# Or using bin prefix:
decimal2 = int('0b101101', 2)
print(decimal2)  # 45

# Decimal to binary string:
print(bin(45))       # '0b101101'
print(bin(45)[2:])   # '101101' (strip '0b' prefix)
print(f'{45:08b}')   # '00101101' (8-bit padded)

Using the Number Base Converter

The Number Base Converter converts between all bases simultaneously:

  1. Select “Binary” as the input base
  2. Type or paste the binary number
  3. See the decimal (and hex, octal) output instantly

Signed vs unsigned binary

Standard binary is unsigned — the number is always positive. 11111111 = 255.

Two’s complement is how computers represent negative numbers in signed integer types. The most significant bit (MSB) is the sign bit:

  • If MSB is 0, the number is positive (same as unsigned)
  • If MSB is 1, the number is negative

To convert a negative two’s complement value:

  1. Flip all bits (one’s complement)
  2. Add 1
  3. The result is the magnitude; apply a negative sign
Two's complement: 1111 0011
Step 1 — flip:   0000 1100
Step 2 — add 1:  0000 1101  = 13
Result: -13

Signed 8-bit range: -128 to +127 Unsigned 8-bit range: 0 to 255

When you see a byte value like 0xFF or 11111111:

  • As unsigned: 255
  • As signed int8: -1

Context determines which interpretation is correct. In most low-level programming, you need to know the type to know the value.

Binary in networking

IP addresses and subnet masks are binary numbers displayed in decimal. An IPv4 address is 32 bits — four 8-bit groups (octets).

IP: 192.168.1.1

192  = 1100 0000
168  = 1010 1000
1    = 0000 0001
1    = 0000 0001

Binary: 11000000.10101000.00000001.00000001

A subnet mask like 255.255.255.0 in binary is 11111111.11111111.11111111.00000000. The 1s represent the network portion, 0s represent the host portion. This is why CIDR /24 means 24 bits for the network (three full octets of 255).

Binary in file permissions (Unix)

Unix file permissions use a 9-bit octal representation:

rwxrwxrwx  →  111 111 111  →  777 (octal)
rwxr-xr-x  →  111 101 101  →  755 (octal)
rw-r--r--  →  110 100 100  →  644 (octal)

Each group of 3 bits represents read (4), write (2), execute (1) for owner, group, others. Binary literacy makes permissions immediately readable.

Binary to hexadecimal shortcut

Every 4 binary digits = 1 hex digit. This is why programmers use hex as a compact binary notation:

Binary:   1010 1111 0011 0101
Group 4:  1010 | 1111 | 0011 | 0101
Hex:       A  |   F  |   3  |   5
Result:   0xAF35

To go the other direction, convert each hex digit to 4 binary digits:

0xB6 = 1011 0110

This shortcut only works cleanly for hex (base 16 = 2⁴). Octal uses 3-bit groups (8 = 2³).


Related posts

Related tool

Number Base Converter

Convert between binary, octal, decimal, hexadecimal, and text (UTF-8). Handles arbitrary lengths. Per-byte and per-character views.

Written by Mian Ali Khalid. Part of the Encoding & Crypto pillar.