Binary, Hex, Octal, Decimal: Number Base Conversion Guide

2026-02-28 4 min read
binaryhexadecimalprogrammingdeveloper-tools

Binary, octal, decimal, and hexadecimal are different ways to represent the same numbers. Understanding base conversion is fundamental for programming, networking, and working with low-level systems.

The bases

BaseNameDigitsCommon use
2Binary0, 1Hardware, bitwise operations
8Octal0-7Unix file permissions
10Decimal0-9Human math
16Hexadecimal0-9, A-FColors, memory addresses, bytes

How base conversion works

In decimal, each position is a power of 10:

  354 = 3×10² + 5×10¹ + 4×10⁰
      = 300   + 50    + 4

In binary, each position is a power of 2:

  1011 = 1×2³ + 0×2² + 1×2¹ + 1×2⁰
       = 8    + 0    + 2    + 1
       = 11 (decimal)

In hexadecimal, each position is a power of 16:

  2F = 2×16¹ + F(15)×16⁰
     = 32    + 15
     = 47 (decimal)

Hexadecimal in practice

Hex is the most commonly encountered non-decimal base:

Colors

#FF6B35 = R:255 G:107 B:53

Each pair of hex digits (00-FF) represents a value from 0-255.

Memory addresses

0x7FFF5FBFFA10

Debuggers and system tools show addresses in hex because they’re more compact than binary.

Byte values

One hex digit = 4 bits. Two hex digits = 1 byte (8 bits). This makes hex a compact representation of binary data.

Binary:  1111 1010
Hex:     F    A

Binary in practice

Bitwise operations

Flags, permissions, and masks use binary:

Read:    100 (4)
Write:   010 (2)
Execute: 001 (1)
R+W+X:   111 (7)

Network masks

255.255.255.0 = 11111111.11111111.11111111.00000000
/24 subnet = 24 ones followed by 8 zeros

Powers of 2

Every programmer should recognize these:

2⁰  = 1
2¹  = 2
2⁸  = 256
2¹⁰ = 1024 (1 KiB)
2¹⁶ = 65536
2³² = 4,294,967,296 (~4.3 billion)

Octal in practice

Octal is mainly used for Unix file permissions:

chmod 755 file.sh

Breaking it down:

  • 7 = rwx (owner: read+write+execute)
  • 5 = r-x (group: read+execute)
  • 5 = r-x (others: read+execute)

Each octal digit maps to 3 binary bits, making it a natural fit for 3-bit permission groups.

Quick conversion table

DecimalBinaryHexOctal
0000000
1000111
5010155
101010A12
151111F17
16100001020
25511111111FF377

Prefixes in code

Different languages denote bases differently:

BaseJavaScriptPythonC
Binary0b10100b10100b1010
Octal0o120o12012
Hex0xFF0xFF0xFF

A number base converter tool handles conversions between all common bases instantly — enter a number in any base and see its representation in all others.

Try it yourself

Use the tool mentioned in this article — free, no sign-up, runs in your browser.

Open Tool