Binary, Hex and Decimal Converter

Convert between binary, octal, decimal, hexadecimal and any base up to 36, with the place values shown so the conversion is visible rather than magic.

In short

To convert decimal to another base, divide repeatedly by the base and read the remainders backwards. To go the other way, multiply each digit by the base raised to the power of its position. Hexadecimal is common in computing because each hex digit maps exactly to four binary digits.

In base 7

—

How the binary breaks down

—
Bits needed
—
Bytes
—
Bits set to 1
—
Smallest type it fits

Last reviewed

Runs entirely in your browser. Nothing you type here is uploaded, stored or logged.

What a base actually means

Every positional number system works the same way. Each digit carries a place value that is the base raised to the power of its position, counting from zero on the right.

In base 10, the number 3,742 means 3 thousands, 7 hundreds, 4 tens and 2 units, which is 3 times 10 cubed plus 7 times 10 squared plus 4 times 10 plus 2. Nothing about that structure requires ten. Replace the base with 2 and the place values become 1, 2, 4, 8, 16 and so on; replace it with 16 and they become 1, 16, 256, 4096.

Base 10 is a biological accident. We have ten fingers. Computers have two voltage states, which is why they count in twos.

Converting by hand

From decimal to another base, divide repeatedly and read the remainders backwards:

156 / 2 = 78 remainder 0
 78 / 2 = 39 remainder 0
 39 / 2 = 19 remainder 1
 19 / 2 =  9 remainder 1
  9 / 2 =  4 remainder 1
  4 / 2 =  2 remainder 0
  2 / 2 =  1 remainder 0
  1 / 2 =  0 remainder 1

read upwards: 10011100

From another base to decimal, multiply each digit by its place value and add:

10011100 = 128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156

The hex shortcut

Because 16 is 2 to the fourth power, every hexadecimal digit corresponds to exactly four binary digits, with no carrying between them. That makes conversion a lookup rather than arithmetic.

1001 1100
   9    C   ->  0x9C

Split the binary into groups of four from the right, convert each group independently, and concatenate. This is the whole reason hexadecimal exists in computing: it is binary that a human can read aloud without losing their place.

Octal does the same with groups of three, which is why Unix permissions are written that way. The mode 755 is 111 101 101, meaning the owner may read, write and execute, while group and others may read and execute only.

Where you actually meet other bases

  • Colours. A hex colour like #1E90FF is three bytes: red 30, green 144, blue 255, each written as two hex digits.
  • File permissions. chmod 644, 755 and 777 are octal, three bits per role.
  • Network masks and addresses. Subnetting is entirely about where the boundary falls in binary, which is why /24 and 255.255.255.0 are the same statement.
  • Hashes and IDs. A SHA-256 digest is 256 bits shown as 64 hex characters. Short URLs and identifiers often use base 36 or base 62 to pack more into fewer characters.
  • Debugging. Memory addresses, error codes and register dumps are conventionally hex, and 0x is the prefix that tells you so.

Powers of two worth knowing

A handful of these come up constantly, and knowing them turns a lot of computing trivia into arithmetic you can do in your head.

2^8  = 256          one byte, 0 to 255
2^10 = 1,024        one kibibyte
2^16 = 65,536       a port number range
2^32 = 4,294,967,296    IPv4 addresses
2^64 = 18.4 quintillion

The 2 to the 32 figure is why IPv4 ran out: roughly four billion addresses for a world with more devices than that. IPv6 uses 128 bits, which is 2 to the 128, a number large enough that running out is not a practical concern.

Why 255 keeps appearing

Eight bits all set to 1 gives 255, the largest value a single byte can hold. That is why colour channels stop at 255, why the last address in a subnet often ends in 255, and why older games capped scores and inventories at 255 or, with a sign bit, at 127.

When a limit in software is 255, 127, 65535 or 32767, you are looking at the edge of a binary type rather than a design decision.

Frequently asked questions

How do I convert decimal to binary by hand?

Divide by 2 repeatedly, writing down each remainder, then read the remainders from bottom to top. 13 divided by 2 gives 6 remainder 1, then 3 remainder 0, then 1 remainder 1, then 0 remainder 1, so 13 is 1101.

How do I convert binary to decimal?

Multiply each digit by 2 raised to the power of its position, counting from zero on the right, and add them. 1101 is 8 plus 4 plus 0 plus 1, which is 13.

Why does computing use hexadecimal?

Because 16 is 2 to the power of 4, so each hex digit maps to exactly four binary digits with no arithmetic needed. The byte 11010110 is D6 by splitting it into 1101 and 0110. Hex is compact binary, which is why it appears in colours, memory addresses and hashes.

What is octal for?

Each octal digit is exactly three bits, which is why Unix file permissions use it: read, write and execute are three bits, so 755 means owner 111 and group and others 101 each. Outside permissions it is largely historical.

What do bases above 16 use for digits?

Letters continue past F. Base 36 uses 0 to 9 then A to Z, which is the largest base expressible with digits and the Latin alphabet. It is used for short identifiers because it packs more value into fewer characters.