Skip to content

Binary, Hex and Decimal Converter

Convert whole numbers between decimal, binary, hexadecimal and octal.

In binary

1111 1111

Binary
1111 1111
Decimal
255
Hexadecimal
FF
Octal
377
Bits needed
8

Good to know. There are 10 kinds of people: those who understand binary and those who don’t.

How it works

In plain words

Every base works the same way: each digit is worth the base times more than the one to its right. To go to another base, divide by the new base repeatedly and read the remainders from the bottom up. Hex is handy because each hex digit is exactly four binary digits.

The formula

value = Σ digit × baseⁿ (n counted from the right, starting at 0)
hex digit ↔ 4 bits · octal digit ↔ 3 bits

Worked example

255 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1, so in binary it is 1111 1111, eight ones. In hex it is FF.

Sources

No outside data or rates: this is plain arithmetic.

5 automated tests check its answers on every change.

About the binary, hex and decimal converter

We count in tens because we have ten fingers, but computers count in twos. Binary uses only 0 and 1; hexadecimal (hex) uses 0 to 9 and A to F for ten to fifteen; octal uses 0 to 7. This converter translates whole numbers between them, of any size.

In every base, each position is worth the base times the one to its right. In decimal, 255 is 2 hundreds, 5 tens and 5 ones. In binary, the positions are 1, 2, 4, 8, 16 and so on, so 255 is 11111111: every position from 1 to 128 switched on. In hex, the positions are 1, 16, 256…, and 255 is F × 16 + F = FF.

Hex is popular with programmers because one hex digit is exactly four bits, so two hex digits make a byte: web colours like #FF8800 are three bytes, red, green and blue. Octal is used for Unix file permissions, where 755 means rwx for the owner and r-x for everyone else.

You can type a prefix: 0x for hex (0xff), 0b for binary and 0o for octal. Spaces and underscores in long numbers are ignored. The last line shows how many bits the number needs; 8 bits make a byte.

Questions people ask

How do I convert decimal to binary?

Divide by 2 again and again, writing down the remainders, then read them from the last to the first. 13 → 6 r1 → 3 r0 → 1 r1 → 0 r1, so 1101.

What is FF in decimal?

255: F is 15, so 15 × 16 + 15 = 255.

How many bits are in a byte?

Eight. A byte can hold numbers from 0 to 255, or 00 to FF in hex.

Put this calculator on your site

Paste this where you want it. It fits the width of the page, grows with the answer and follows your readers’ dark mode. Free, with no ads inside.

<a href="https://99solved.com/number-base-converter" data-99solved>Binary, Hex and Decimal Converter</a>
<script async src="https://99solved.com/embed.js"></script>