Skip to content

Number base converter

Math & numbers

How do you convert a number between bases?

Convert whole numbers between binary, octal, decimal, hexadecimal and any base up to 36.

In hexadecimal

ff

3 digits read in base 10

The same number in other bases

In binary
11111111
In octal
377
In decimal
255

Sponsored Links

Convert whole numbers between binary, octal, decimal, hexadecimal and any base up to 36.

How to use

  1. Type the number. Digits above 9 are letters: A or a is ten, F is fifteen.
  2. Choose the base it is written in, then the base to convert to. 10 is the everyday decimal, 2 binary, 8 octal and 16 hexadecimal.
  3. Copy the result. The same number is also shown in the other common bases.

How it works

A base says how many digits a numbering system has, and each place is worth that many times the one to its right. In decimal the places are ones, tens, hundreds. In binary they are ones, twos, fours, eights. In hexadecimal, which has 16 digits (0–9 and A–F), they are ones, sixteens, 256s and so on. Computers use binary, and hexadecimal is a compact way to write it: one hex digit is exactly four binary digits.

To convert, add up each digit times the value of its place. For example hex FF is 15 × 16 + 15 = 255, which is 11111111 in binary and 377 in octal. Going the other way, divide by the new base again and again and read the remainders backwards (Knuth, The Art of Computer Programming, vol. 2, section 4.1).

This tool works with whole numbers of any size, so a 64-bit or even larger value stays exact, and accepts bases from 2 to 36, where the letters a to z are the digits ten to thirty-five. You can type spaces or underscores to group digits, a minus sign, and the usual 0x, 0b and 0o prefixes. Fractions are not converted.

Worked example

What is hexadecimal 2A in decimal?

  1. Its digits represent 2 × 16 + 10.

The decimal value is 42.

Sponsored Links

Frequently asked questions

Why do programmers use hexadecimal?

It is a short way to write binary: every hex digit stands for exactly four bits, so a byte is two hex digits, such as FF.

What does the 0x in front of a number mean?

It marks a hexadecimal number in many programming languages. 0b marks binary and 0o octal. You can leave it in or out here.

Why does it say a digit is not valid?

Each base has only as many digits as its number. Base 8 has 0 to 7, so 9 cannot appear, and base 2 only has 0 and 1. Check the base the number is written in.

Does uppercase change a hexadecimal number’s value?

No. A–F and a–f represent the same digits. Uppercase changes only how the result is written.

Are negative values shown in two’s complement?

No. The converter keeps a minus sign. Two’s complement needs a chosen bit width and is not calculated here.

Sponsored Links

Sponsored Links