UtilityBase logoUtilityBase

3 min read

How Number Bases Work: Binary, Hex, Octal, and Decimal

How positional notation lets the same value be written in base 2, 8, 10, or 16, how to convert by hand, and where two's complement comes in.

Positional notation is the whole idea

Every base uses positional notation: each digit is multiplied by the base raised to the power of its position, counting from zero on the right. In decimal, 205 means 2 times 100 plus 0 times 10 plus 5 times 1. The only thing that changes between bases is the base number and how many distinct digits are available.

Binary (base 2) uses digits 0 and 1, octal (base 8) uses 0 through 7, decimal (base 10) uses 0 through 9, and hexadecimal (base 16) uses 0 through 9 then A through F for the values ten through fifteen. The same quantity thirteen is 1101 in binary, 15 in octal, 13 in decimal, and D in hex.

Why programmers use hex and octal

Hexadecimal is popular because one hex digit maps to exactly four binary digits, so a byte of eight bits is always two clean hex digits. This makes hex a compact, readable stand-in for binary, which is why colors like #FF8800 and memory addresses are written in hex.

Octal groups bits in threes and survives mainly in Unix file permissions, where read, write, and execute map neatly onto three bits per digit. Both bases exist because they compress binary without hiding its structure the way decimal does.

Converting between bases by hand

To convert a decimal number to another base, repeatedly divide by the target base and collect the remainders from last to first. To go the other way, multiply each digit by the base raised to its position and add the results. Converting between binary and hex is faster: split the binary into groups of four bits from the right and translate each group into one hex digit.

Fractional values follow the same logic on the other side of the point, using negative powers of the base, though many fractions that are exact in decimal, like 0.1, repeat forever in binary.

Converting with the tool

The Number Base Converter takes a value in one base and shows it in binary, octal, decimal, and hexadecimal at once, so you can check your hand work or skip it entirely.

  1. 1Enter your number in the field for the base you already have, such as decimal or hex.
  2. 2Read the equivalent values shown in the other bases.
  3. 3Confirm the input uses only digits valid for its base, since a hex value can include A through F but a binary one cannot.
  4. 4Copy the base you need into your code, calculator, or config file.
  5. 5For a negative or very large value, note how many bits your target system uses before relying on the result.

Negative numbers and two's complement

Bases themselves have no sign; a raw binary string is just a magnitude. Computers store negative integers using two's complement, where the leftmost bit carries a negative weight. In an 8-bit two's-complement byte, 11111111 is not 255 but -1, because the value depends on the fixed bit width.

This is the caveat that trips people up: the same bit pattern means different things depending on whether it is read as unsigned or signed, and on how many bits the register holds. A plain base conversion assumes an unsigned magnitude unless you specify the width and signing convention.

Frequently asked questions

Why does hexadecimal use letters?

Base 16 needs sixteen distinct digit symbols, but we only have ten numerals, so the letters A through F stand in for the values ten through fifteen. They are digits, not words.

How can one hex digit replace four binary digits?

Four bits can represent sixteen combinations, exactly the range of a single hex digit from 0 to F. That clean mapping is why hex is used as shorthand for binary.

Why does 11111111 sometimes mean 255 and sometimes -1?

As an unsigned 8-bit number it is 255, but under two's-complement signed interpretation the top bit is negative, making it -1. The meaning depends on the bit width and whether the value is signed.

Tools mentioned in this guide

Keep reading