Representing integers in different bases

Integers can be expressed in base 10 or in any other numeral base through a positional representation. In general, an integer can be written in the form $$ n = r_k b^k + r_{k-1} b^{k-1} + \dots + r_0 b^0 $$

Here, n denotes the integer being represented, b is the chosen base, and k is a nonnegative integer corresponding to the highest power of the base. The indices decrease from left to right, reflecting digit positions counted from right to left.

A concrete example

The number n = 247 in base 10 can be written as

$$ 247 = 2 \cdot 10^2 + 4 \cdot 10^1 + 7 \cdot 10^0 $$

The rightmost digit represents the units, the next digit represents the tens, and the third represents the hundreds.

How are the digits determined?

Each digit is obtained as the remainder when the number is divided by 10.

$$ 247 : 10 = 24 \:\:\:\text{with remainder } r = 7 $$

$$ 24 : 10 = 2 \:\:\:\text{with remainder } r = 4 $$

$$ 2 : 10 = 0 \:\:\:\text{with remainder } r = 2 $$

Reading the remainders from the last division to the first reconstructs the number 247.

Converting a number from base 10 to other bases

To change the base of a number, one can use a standard and efficient algorithm: repeatedly divide the number by the new base and record the remainder at each step as a digit of the new representation, continuing until the quotient becomes zero.

Example

To express the number 247 in base two (b = 2), we repeatedly divide the number by 2.

$$ 247 : 2 = 123 \:\:\:\text{with remainder } r = 1 $$

$$ 123 : 2 = 61 \:\:\:\text{with remainder } r = 1 $$

$$ 61 : 2 = 30 \:\:\:\text{with remainder } r = 1 $$

$$ 30 : 2 = 15 \:\:\:\text{with remainder } r = 0 $$

$$ 15 : 2 = 7 \:\:\:\text{with remainder } r = 1 $$

$$ 7 : 2 = 3 \:\:\:\text{with remainder } r = 1 $$

$$ 3 : 2 = 1 \:\:\:\text{with remainder } r = 1 $$

$$ 1 : 2 = 0 \:\:\:\text{with remainder } r = 1 $$

By concatenating the remainders from the last obtained to the first, we obtain the representation of the number in base two, namely its binary representation.

$$ (247)_{10} = (11110111)_{2} $$

 
 

Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

FacebookTwitterLinkedinLinkedin
knowledge base