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.

Results

Base N Convert -

Tag(s) : Arithmetics

Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Thanks to your feedback and relevant comments, dCode has developed the best 'Base N Convert' tool, so feel free to write! Thank you!

# Base N Convert

## Converting Base 10 to Base N

### 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 bases, it is common to use letters, more precisely the following characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ (Beware to lowercase and uppercase from base 37) in order to write numbers up to base 62.

### 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 + 9 \times 1 = 7 \times 10^2 + 8 \times 10^1 + 9 \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 to 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 - base2) in informatics

— base 3 (trinary system - base3)

— base 8 (octal system - base8)

— base 9 (nonary system - base9)

— base 10 (decimal system - base10)

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

— base 16 (hexadecimal system - base16) in informatics for bytes

— base 20 (vigesimal system - base20) by Mayas and Aztecs

base 26 (alphabetic system - base26)

base 36 (alphanumeric system - base36)

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

base 62 (full alphanumeric system - base62)

All the basics can be used for computer coding or any other math problem.

Example: Encoding and decoding base64 is common on the Internet.

## Source code

dCode retains ownership of the online "Base N Convert" source code. Except explicit open source licence (indicated CC / Creative Commons / free), the "Base N Convert" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or the "Base N Convert" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, copy-paste, or API access for "Base N Convert" are not public, same for offline use on PC, tablet, iPhone or Android ! Remainder : dCode is free to use.

## Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!