Search for a tool
Base N Convert

Tool to write numbers in base N (change of basis / convert). In numeral systems, a base (radix) is the value of successive powers when writing a number. Until base 10, it is common to use digits 0, 1, 2, 3, 4, 5, 6, 7, 8 et 9, after, some others symbols such as letters.

Results

Base N Convert -

Tag(s) : Arithmetics

dCode and you

dCode is free and its tools are a valuable help in games, puzzles and problems to solve every day!
You have a problem, an idea for a project, a specific need and dCode can not (yet) help you? You need custom development? Contact-me!

Team dCode read all messages and answer them if you leave an email (not published). It is thanks to you that dCode has the best Base N Convert tool. Thank you.

# Base N Convert

## Converting Base 10 to Base N

Tool to write numbers in base N (change of basis / convert). In numeral systems, a base (radix) is the value of successive powers when writing a number. Until base 10, it is common to use digits 0, 1, 2, 3, 4, 5, 6, 7, 8 et 9, after, some others symbols such as letters.

### What are default symbols?

A number in base 10 is written with the digits' 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9` are used. For other databases, it is customary to use the following characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ (Beware to lowercase and uppercase from base 37)

### How to convert from a base to another?

A number $$N$$ in base $$b$$ can be written with an addition of powers in this base $$b$$.

Example: The number $$N = 123_{(10)}$$ (base 10) verifies the equality $$N = 789 = 7 \times 100 + 8 \times 10 + 7 \times 1 = 7 \times 10^2 + 8 \times 10^1 + 7 \times 10^0$$

 $$N=$$ $$c2$$ $$c1$$ $$c0$$ $$789$$ $$7$$ $$8$$ $$9$$

Take a number $$N$$ made of $$n$$ digits $${ c_{n-1}, c_{n-2}, ..., c_2, c_1, c_0 }$$ in base $$b$$, it can be written it as a polynomial:

$$N_{(b)} = \{ c_{n-1}, ..., c_1, c_0 \}_{(b)} = c_{n-1} \times b^{n-1} + ... + c_1 \times b^1 + c_0 \times b^0$$

To compute a base change, base $$10$$ is the reference, or an intermediate step.

Example: To change from base $$3$$ to base $$7$$, calculate base $$3$$ to base $$10$$, then from base $$10$$ to base $$7$$.

### How to convert from base 10 to base n?

Use the following algorithm to convert from base $$10$$ to base $$n$$:

$$q_0=n; i=0; \mbox{ while } q_i > 0 \mbox{ do } (r_i = q_i \mbox{ mod } b; q_{i+1}= q_i \mbox{ div } b ; i = i+1 )$$

The converted number is composed of digits $$r_{i=0...n-1}$$ (with $$r_0$$ the digit of the units).

Example: $$N = 123_{(10)}$$ (base 10) is converted in base $$7$$:

$$q_0 = 123 \\ r_0 = 123 \mbox{ mod } 7 = 4 \;\;\; q_1 = 123 \mbox{ div } 7 = 17 \\ r_1 = 17 \mbox{ mod } 7 = 3 \;\;\; q_1 = 17 \mbox{ div } 7 = 2 \\ r_2 = 2 \mbox{ mod } 7 = 2 \;\;\; q_2 = 2 \mbox{ div } 7 = 0 \\ 123_{(10)} = 234_{(7)}$$

### How to convert from base n to base 10?

To convert a number $$N_1$$ written in base $$b$$ in a number $$N_2$$ written in base $$10$$, use the fact that $$N_1$$ is made of $$n$$ digits $${ c_{n-1}, c_{n-2}, ..., c_1, c_0 }$$ and apply the following algorithm:

$$N_2 = c_{n-1} ; \mbox{ for } ( i=n-2 \mbox{ to } 1 ) \mbox{ do } N_2=N_2 \times b+c_i$$

The number $$N_2$$ is written in base $$10$$.

The algorithm is equivalent to the calculation $$(( c_{n-1} \times b + c_{n-2} ) \times b + c_{n-3} ) ... ) \times b + c_0$$

Example: Take the number $$123_{(7)}$$ (in base $$7$$), and apply the conversion algorithm:

$$123 = \{1,2,3\} \\ N = 1 \\ N = 1*7+2 = 9 \\ N = 9*7+3 = 66 \\ N = 123_{(7)} = 66_{(10)}$$

So $$123_{(7)}$$ is equal to $$66_{(10)}$$ in base $$10$$.

### What are usual bases?

- base 2 (binary system) in informatics

- base 3 (trinary system)

- base 8 (octal system)

- base 9 (nonary system)

- base 10 (decimal system)

- base 12 (duodecimal system), for month or hours

- base 16 (hexadecimal system) in informatics for bytes

- base 20 (vigesimal system) by Mayas and Aztecs

- base 26 (alphabetic system)

- base 36 (alphanumeric system)

- base 60 (sexagesimal system) for minutes, seconds by Sumerians and Babylonians.

- base 62 (full alphanumeric system)