Tool to write numbers in base N. 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.

Base N Convert - dCode

Tag(s) : Mathematics, Arithmetics

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*!

Sponsored ads

Tool to write numbers in base N. 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.

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 \) |

Consider 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 \).

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)} $$

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: Consider 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 \).

- 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)

dCode retains ownership of the source code of the script Base N Convert online. Except explicit open source licence (indicated Creative Commons / free), any algorithm, applet, snippet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in any informatic langauge (PHP, Java, C#, Python, Javascript, etc.) which dCode owns rights can be transferred after sales quote. So if you need to download the online Base N Convert script for offline use, for you, your company or association, see you on contact page !

base,convert,change,modulo,decimal,octal,binary,hexadecimal,system,digit,number,letter

Source : https://www.dcode.fr/base-n-convert

© 2018 dCode — The ultimate 'toolkit' to solve every games / riddles / geocaches. dCode