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.

Base N Convert - dCode

Tag(s) : Arithmetics

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

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.

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.

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 $.

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

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 $.

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

dCode retains ownership of the online 'Base N Convert' tool source code. Except explicit open source licence (indicated CC / Creative Commons / free), any algorithm, applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (PHP, Java, C#, Python, Javascript, Matlab, etc.) no data, script or API access will be for free, same for Base N Convert download for offline use on PC, tablet, iPhone or Android !

Please, check our community Discord for help requests!

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

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

© 2020 dCode — The ultimate 'toolkit' to solve every games / riddles / geocaching / CTF.

Feedback

▲