← All concepts
TechnologyBasic theoryInteractive

Number systems

Binary, octal, decimal and hex — how to convert between them, plus bits, bytes, and two's complement.

Number base converter
Binary
101010
Octal
52
Decimal
42
Hex
2A
Two's complement
8-bit00101010
16-bit0000000000101010

A positional number system gives each digit a weight that is a power of the base (radix). Decimal is base 10; computers work in base 2 because a wire is either on or off.

The common bases

BaseNameDigits used
2Binary0 1
8Octal0–7
10Decimal0–9
16Hexadecimal0–9, A–F

Converting

  • To decimal: multiply each digit by its positional weight and sum. 1011₂ = 8+0+2+1 = 11₁₀.
  • From decimal: repeatedly divide by the base; the remainders, read bottom-up, are the digits.
  • Binary ↔ hex: group binary into 4-bit *nibbles*; each nibble is one hex digit. 11111010₂ = FA₁₆.
  • Binary ↔ octal: group into 3-bit sets; each set is one octal digit.

Units

  • 1 bit = one binary digit (0 or 1).
  • 1 nibble = 4 bits = one hex digit.
  • 1 byte = 8 bits = two hex digits, holding values 0–255.

Two's complement (signed integers)

To store negatives, computers use two's complement: invert every bit of the magnitude and add 1. In *n* bits the range is −2ⁿ⁻¹ … 2ⁿ⁻¹−1 — for 8 bits that's −128…127. The most-significant bit acts as the sign.

Tip:Use the converter above — type a value in any base and watch the others update, including the 8- and 16-bit two's-complement forms.