Skip to the content

Number Base Converter

Binary, octal, decimal and hexadecimal, or any base from 2 to 36.

Type in any field and the others follow. Whole numbers only; a minus sign makes them negative. The prefixes 0b, 0o and 0x, spaces and underscores are all fine.

from 2 to 36
Bit length
8 bits
Fits in
1 byte
Share this tool:TwitterFacebookLinkedInWhatsAppEmail

How positional notation works

In a decimal number every place is worth ten times the place to its right: 202 is 2 × 100 + 0 × 10 + 2 × 1. Other bases work the same way with a different multiplier. In binary each place is worth twice the next one (…, 8, 4, 2, 1), in octal eight times (64, 8, 1), in hexadecimal sixteen times (256, 16, 1).

A base needs as many digits as its number says. Hexadecimal borrows letters for the digits past 9: A is 10, B is 11, up to F for 15. Going on through the alphabet, Z is 35, which is why 36 is the highest base here: ten digits plus twenty-six letters.

From another base to decimal

Multiply every digit by the worth of its place and add the results.

  • Binary 11001010 = 128 + 64 + 8 + 2 = 202
  • Octal 312 = 3 × 64 + 1 × 8 + 2 × 1 = 202
  • Hexadecimal CA = 12 × 16 + 10 × 1 = 202

From decimal to another base

Keep dividing by the base and note the remainders. Read from the last remainder back to the first, they are the digits. For 202 in binary:

DivisionResultRemainder
202 ÷ 21010
101 ÷ 2501
50 ÷ 2250
25 ÷ 2121
12 ÷ 260
6 ÷ 230
3 ÷ 211
1 ÷ 201

From the bottom up that reads 11001010. For hexadecimal one step is enough: 202 ÷ 16 = 12 remainder 10, and the digits for 12 and 10 are C and A.

Why bytes are written in hexadecimal

Sixteen is 2⁴, so one hexadecimal digit stands for exactly four bits, and a byte of eight bits is always two digits. Going between binary and hexadecimal takes no arithmetic: split the bits into groups of four from the right and translate each group.

BitsHexBitsHex
0000010008
0001110019
001021010A
001131011B
010041100C
010151101D
011061110E
011171111F

1100 1010 is therefore C and A. That is why colour codes such as #FF8800, memory addresses and MAC addresses are written in hexadecimal: it is binary in a quarter of the space. Octal does the same with groups of three bits (11 001 010 is 312) and lives on in Unix file permissions such as chmod 755.

Negative numbers and two's complement

The fields show a negative number the way you would write it on paper, with a minus sign: −202 is -11001010. A computer has no minus sign. It stores a negative number in a fixed number of bits as 2ⁿ minus its size. In 8 bits, −56 becomes 256 − 56 = 200, the pattern 1100 1000. The shortcut gives the same result: take 56 (0011 1000), flip every bit (1100 0111) and add 1.

The pattern alone does not say which number was meant: 1100 1000 is −56 when read with a sign and 200 without. That is also why a signed byte runs from −128 to 127 and an unsigned one from 0 to 255. Switch on the two's complement view to see both readings for 8, 16, 32 or 64 bits.

What it does not do

Only whole numbers are converted. Fractions are a different matter: 0.1 has no finite binary form at all.

Length is not a limit. The arithmetic is done on whole numbers of unlimited size (up to 10,000 digits per field), so a 64-bit value or a 200-digit number comes out exact. A converter that stores numbers as floating-point values goes wrong above 2⁵³, which is 9,007,199,254,740,992.

See all 9