Base Conversion: Binary, Octal and Hexadecimal

Converts a decimal integer to the given base (2 to 36). Digits above 9 are written A, B, C … . The binary, octal and hexadecimal forms are also shown.

This converts a decimal integer into any base from 2 to 36.

In base nn every digit carries a weight that is a power of nn, just as the decimal system we use every day weights its digits by powers of ten. In binary those weights are powers of two.

255=1×27+1×26++1×20255 = 1 \times 2^7 + 1 \times 2^6 + \cdots + 1 \times 2^0

The method is mechanical: divide by the base, note the remainder, divide the quotient again. Keep going until the quotient reaches 0, then read the remainders from the bottom up.

Example

Convert decimal 255 to binary. Dividing by 2 leaves a remainder of 1 every single time, and after eight steps the quotient hits 0. Reading the remainders from the bottom up gives

255(10)=11111111(2)255_{(10)} = 11111111_{(2)}

Since 255=2561=281255 = 256 - 1 = 2^8 - 1, the answer is exactly eight 1s. The same number is 377 in octal and FF in hexadecimal.

Notes