WWeHelpDevs
TutorialSeptember 10, 2026·6 min read

Binary, Octal, Decimal, Hex: Number Systems Explained

Why programmers actually use binary, octal, and hexadecimal, how to convert between bases by hand, and where each base still shows up in real code.

Number bases feel like a computer-science-class abstraction until you run into a bitwise flag constant, a file permission like chmod 755, or a color value like #ff6b35, all of which are quietly using a different base than the decimal numbers you use everywhere else. Understanding what's actually happening under each notation makes all three click into place at once.

Positional Notation Is the Same Idea Every Time

Every positional number system — decimal, binary, octal, hex — works identically: each digit's value depends on its position, multiplied by the base raised to that position's power. Decimal (base 10) just happens to be the one we learned first:

decimal present as base-10 positions:
   347 = 3×10² + 4×10¹ + 7×10⁰

binary (base 2) works the same way, just with fewer digit symbols (0, 1):
  1011 = 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11 (decimal)

Once this clicks, converting to decimal from any base is mechanical: multiply each digit by the base raised to its position, and sum.

Binary: What the Computer Actually Sees

Binary (base 2) uses only 0 and 1, because that maps directly onto a transistor being off or on — it's not a human convenience, it's the literal hardware representation everything else is built on top of. This is why bitwise operations are expressed and reasoned about in binary rather than decimal:

const flags = 0b1011   // binary literal in JS: 11 in decimal
const READ  = 0b0001
const WRITE = 0b0010
const EXEC  = 0b0100

const canWrite = (flags & WRITE) !== 0   // bitwise AND — only makes visual sense in binary

Trying to reason about flags & WRITE using the decimal values 11 & 2 obscures exactly what's being checked; writing it in binary (1011 & 0010) makes it visually obvious you're testing a single bit position.

Octal: Mostly a Unix Legacy Now

Octal (base 8, digits 0–7) rarely appears in modern application code, but it survives in one very common place: Unix file permissions.

chmod 755 file.sh

Each octal digit represents a permission triple (read=4, write=2, execute=1) for owner, group, and others — 7 = 4+2+1 = read+write+execute, 5 = 4+0+1 = read+execute. This is a genuinely elegant use of octal: three independent bits (rwx) fit exactly into one octal digit's three-bit range (0–7), which is no accident — octal was popular specifically because 3 bits map cleanly to one digit, the same reason hex (4 bits per digit) took over for most other use cases.

Hexadecimal: The Practical Default for Representing Bytes

Hex (base 16) uses digits 0–9 plus A–F for values 10–15. Its appeal is almost entirely practical: one hex digit represents exactly 4 bits (a "nibble"), so two hex digits represent exactly one byte (8 bits) — a clean, compact mapping that binary (8 characters per byte) and decimal (an awkward, non-power-of-two base) don't offer.

binary:  11111111
hex:     FF        (2 characters instead of 8)
decimal: 255

This is exactly why hex shows up wherever raw byte values need to be written compactly and precisely: memory addresses, color codes (#3b82f6 — three bytes, one per RGB channel), MAC addresses, hash digests, and Base64's less-common cousin for representing binary as text.

Converting Between Bases

For decimal → any base, repeatedly divide by the target base and read the remainders in reverse:

Convert 45 to binary:
45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 =  5 remainder 1
 5 ÷ 2 =  2 remainder 1
 2 ÷ 2 =  1 remainder 0
 1 ÷ 2 =  0 remainder 1
Read remainders bottom to top: 101101

For any base → decimal, multiply each digit by the base raised to its position and sum (as shown earlier). Converting binary ↔ hex directly is faster than going through decimal at all: group binary digits into sets of 4 from the right, and each group maps to exactly one hex digit:

binary:  1011 1111
hex:      B    F     →  0xBF

This grouping trick is why hex is often called a "human-friendly shorthand for binary" — there's no lossy conversion or awkward math involved, just a direct regrouping.

When to Reach for Which

  • Binary — bitwise flags, permission masks, anywhere you're reasoning about individual bits.
  • Octal — almost exclusively Unix file permissions at this point; rare elsewhere in modern code.
  • Hex — colors, memory addresses, hashes, byte-level data of any kind — the practical default whenever raw bytes need a compact, precise text representation.
  • Decimal — everything meant for humans to read as a quantity — counts, prices, measurements.

For quick one-off conversions between any of these, our Number Base Converter handles binary, octal, decimal, and hex simultaneously as you type, which is faster and less error-prone than doing the division-and-remainder method by hand for anything beyond a quick sanity check.

Summary

  • All positional number systems work the same way — only the base and digit symbols change; converting to decimal is always digit × base^position, summed.
  • Binary maps directly to hardware (on/off transistors); it's why bitwise logic is reasoned about in binary, not decimal.
  • Octal survives mainly in Unix file permissions, where 3 bits map cleanly to one digit.
  • Hex is the practical default for representing bytes compactly (2 hex digits = 1 byte) — colors, hashes, and addresses all use it for this reason.
← All articles

Enjoyed this article?

Get new tutorials and guides in your inbox every week. Free, no spam.

Subscribe to WeHelpDevs →