Skip to content
Math & Statisticsnumber theory

Number Base Converter

Whole numbers converted between binary, octal, decimal, hexadecimal and base 36, with the bit width and an optional zero padding. Hexadecimal exists because one hex digit is exactly four bits, which is why memory addresses are written in it and not in decimal.

Also called: binary converter, hex to decimal converter.

Converted value
11111111

255 in base 10 is 11111111 in base 2, which is 255 in decimal. The value needs 8 bits, so it fits in a single byte. In base 2 it takes 8 digits, against 3 in decimal. Bases that are powers of two convert to binary by regrouping digits. Decimal has no such relationship to the bits, which is why computing uses hex and octal instead.

In decimal
255
Binary
11111111
Octal
377
Hexadecimal
FF
Bits required
8
Digits in the result
8
On the digits
The value needs 8 bits, so it fits in a single byte. In base 2 it takes 8 digits, against 3 in decimal.
On representation
Bases that are powers of two convert to binary by regrouping digits. Decimal has no such relationship to the bits, which is why computing uses hex and octal instead.

The same value in several bases

BaseValueDigits
2, binary111111118
8, octal3773
10, decimal2553
16, hexFF2
36732
Method and background

How this is calculated

A number in any base is the sum of its digits multiplied by powers of that base, so converting means evaluating that sum and then repeatedly dividing by the target base to read the new digits off the remainders. Bases that are powers of two convert to and from binary without arithmetic at all: one octal digit is three bits and one hexadecimal digit is four, so the conversion is regrouping rather than calculating. That property is the whole reason hexadecimal is used in computing, where decimal has no such relationship to the underlying bits.

each digit is worth its face value times the base raised to its position, which is the definition every base shares
d_k
Digit at position k
b
Base

Worked examples

Each of these is asserted on every build. If a change to the engine ever moved one of these answers, the build would fail before the page could print it.

255 into binary

Value
255
From base
Decimal, base 10
To base
Binary, base 2
Pad binary to this many bits
0

Converted value11111111

the largest value a single byte holds

Open this example

hex back to decimal

Value
FF
From base
Hexadecimal, base 16
To base
Decimal, base 10
Pad binary to this many bits
0

Converted value255

boundary: the round trip must return the same value

Open this example

Written about this

Method and limits

What it assumes

  • Whole numbers, since a fraction rarely terminates in a different base.

What it deliberately does not model

  • Fractional values are not converted, because a terminating fraction in one base often repeats forever in another.
  • Values above the safe integer range lose precision.

Formula version 1.0.0 · definition 1.0.0 · India · Report a problem with this calculator

Frequently asked questions

Why is hexadecimal used in computing?
Because one hex digit is exactly four bits. A byte is two hex digits, so a hex value maps onto the bits without arithmetic, which decimal cannot do.
Why not convert decimal fractions?
Because a fraction that terminates in one base usually repeats forever in another. A tenth is exact in decimal and infinitely repeating in binary, which is the source of most floating point surprises.