belun.app Blog RU

Binary, Octal, Decimal, and Hex: A Developer's Guide to Number Bases

Why computers use binary and hex, how to convert between number bases, and when each system shows up in real-world code.

Binary code streaming across a dark computer screen — number base conversion for developers

Most developers deal with at least three number bases on a regular basis without thinking much about it. You type a port number (decimal), look at a CSS color (#FF5733 — that’s hex), and then curse at a stack trace showing a memory address in hex. And once in a while, Unix file permissions drag octal back into the picture.

The Number Base Converter lets you type in any base and see the other three instantly — no mental arithmetic required.

Why computers use binary

Computers store everything as sequences of 1s and 0s because transistors have two stable states: on and off. That’s it. There’s no physical mechanism for “kind of on” at the hardware level. So every number, every character, every pixel color ultimately lives in binary.

A single binary digit is a bit. Eight bits make a byte. And a byte can hold values from 0 (00000000) to 255 (11111111).

Hexadecimal: binary’s compact cousin

Binary gets unwieldy fast. The decimal number 255 is 11111111 in binary — eight characters for a number you’d normally write in three. Hexadecimal solves this by grouping four bits into a single digit.

Hex uses 0–9 for the first ten values, then A–F for ten through fifteen. One hex digit = four bits. Two hex digits = one byte. So 255 in decimal is FF in hex — much shorter, and still a direct mapping to binary (F = 1111, F = 1111).

This is why you see hex everywhere in programming:

  • CSS colors: #1A2B3C — each pair is one color channel (red, green, blue), one byte each
  • Memory addresses: 0x7fff5fbff8a0 — printed in hex because it’s shorter and aligns with byte boundaries
  • SHA-256 hashes: 64 hex characters = 256 bits
  • ASCII and Unicode codepoints: U+0041 is the letter A

Octal: the chmod relic

Octal (base 8, using digits 0–7) was more common before hex took over. Its main survivor today is Unix file permissions.

When you run chmod 755 script.sh, those digits are octal. Each digit represents three bits, one for each of read, write, and execute:

  • 7 = 111 in binary = read + write + execute
  • 5 = 101 in binary = read + execute (no write)
  • 4 = 100 in binary = read only

So 755 means: owner can do everything, group and others can read and execute but not write. Three octal digits, nine permission bits, one command.

Converting between bases

The process is always the same: convert to decimal as an intermediate step, then convert to the target base.

Binary 1101 → decimal: work right to left, multiply each bit by its positional value (2⁰, 2¹, 2², 2³):

  • 1 × 1 = 1
  • 0 × 2 = 0
  • 1 × 4 = 4
  • 1 × 8 = 8
  • Total: 13

Decimal 13 → hex: divide repeatedly by 16 and collect remainders. 13 ÷ 16 = 0 remainder 13. Remainder 13 = D. So 13 decimal is D hex.

Nobody does this by hand anymore. The Number Base Converter handles the arithmetic — type in any field and the rest update immediately.

Where you’ll actually use this

A few real situations where switching bases matters:

Bit flags. If you’re setting flags in a byte, binary makes the bit positions obvious. 0b10110000 is clearer than 176 when you care which specific bits are set.

Color manipulation. #FF8800 is easier to adjust by channel than converting to decimal first. FF is 255, 88 is 136, 00 is 0 — you can see red is maxed, green is mid, blue is zero.

IP and network ranges. CIDR notation and subnet masks are easier to reason about once you’re comfortable converting between decimal and binary.

Debugging serialized data. Protocol buffers, CBOR, and other binary formats show raw bytes in hex in most debuggers. Knowing that 0x01 is just 1 and 0xFF is 255 makes reading these dumps faster.


Open the Number Base Converter, type any number in whichever base you already know, and read off the rest — no math, no lookup tables.

Try the tool

Number Base Converter →