Cadmeo

Binary Converter

Binary : base 2

0010 1010

Octal : base 8

052

Decimal : base 10

42

Hexadecimal : base 16

2A

The binary converter takes a number in any of four bases (binary, octal, decimal or hexadecimal) and shows it in all four at once. That covers every direction in one page rather than needing a separate tool for each pair, and it makes the relationships between the bases visible.

How it works

A positional number system multiplies each digit by its base raised to the digit position. The bases here are chosen because three of them are powers of two, which makes conversion between them a matter of regrouping digits rather than doing arithmetic.

  • Binary to hex: each group of four binary digits is exactly one hex digit. 1111 is F, always.
  • Binary to octal: each group of three binary digits is exactly one octal digit.
  • Decimal is the odd one out. It is not a power of two, so converting to or from it needs real division.
  • Grouping follows the convention for each base: four digits for binary, two for hex, three for octal.

Input accepts the conventional prefixes 0b, 0o and 0x, and ignores spaces and underscores, so you can paste a grouped value straight back in.

Examples

Decimal to the other three bases

Value

42

Input base

Decimal

Result

Binary 10 1010 · Octal 052 · Hexadecimal 2A

42 = 32 + 8 + 2, which is bits 5, 3 and 1 set. Reading the binary in groups of four from the right gives 2A in hex directly.

Hexadecimal to binary

Value

FF

Input base

Hexadecimal

Result

Binary 1111 1111 · Decimal 255 · Octal 377

Each hex digit maps to exactly four binary digits, so FF is two groups of 1111. This is why hex is used to write byte values. One byte is always two hex digits.

An invalid digit

Value

1012

Input base

Binary

Result

Flagged as not valid in base 2

Binary has no digit 2. Many converters silently parse up to the invalid character and return 5 for this input, which is worse than an error.

Frequently asked questions

Why is hexadecimal used so much in computing?

Because one hex digit is exactly four binary digits, so a byte is always exactly two hex digits with no arithmetic needed to convert. Decimal has no such relationship to binary, which is why memory addresses, colour codes and byte dumps are all written in hex.

What do the 0b, 0o and 0x prefixes mean?

They mark the base in most programming languages: 0b for binary, 0o for octal, 0x for hexadecimal. The tool accepts them on input and strips them, so you can paste a literal straight out of code.

Why does the converter reject 1012 as binary instead of returning a number?

Because binary has no digit 2, so the input is wrong. Many converters use a parse function that stops at the first invalid character and returns a partial result, 5 in this case, which hides the mistake. Reporting the error is more useful than guessing.

Why is octal still around?

Mostly Unix file permissions, where each of the three permission bits (read, write, execute) forms one octal digit, which is why chmod 755 is written that way. It was also common on early machines with word sizes divisible by three.