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!
The base (or radix) is the number of distinct digits needed to write the numbers (in a positional numeral system).
Example: In decimal base, the base used by default to write numbers, 10 digits are used: from 0 to 9, so it is a writing in base 10.
A number N in base/radix 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×100+8×10+9×1=7×102+8×101+9×100
N= | c2 | c1 | c0 |
789 | 7 | 8 | 9 |
Take a number N made of n digits cn−1,cn−2,⋯,c2,c1,c0 in base b, it can be written it as a polynomial:
N(b)={cn−1,⋯,c1,c0}(b)=cn−1×bn−1+⋯+c1×b1+c0×b0
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.
A number in base/radix 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.
Use the following algorithm to convert/encode from base 10 to base n:
q0=n;i=0; while qi>0 do (ri=qi mod b;qi+1=qi div b;i=i+1)
The converted number is composed of digits ri=0⋯n−1 (with r0 the digit of the units).
Example: N=123(10) (base 10) is converted to base 7:
q0=123r0=123 mod 7=4q1=123 div 7=17r1=17 mod 7=3q1=17 div 7=2r2=2 mod 7=2q2=2 div 7=0123(10)=234(7)
To convert/decode a number N1 written in base b in a number N2 written in base 10, use the fact that N1 is made of n digits cn−1,cn−2,⋯,c1,c0 and apply the following algorithm:
N2=cn−1; for (i=n−2 to 1) do N2=N2×b+ci
The number N2 is written in base 10.
The algorithm is equivalent to the calculation ((cn−1×b+cn−2)×b+cn−3)⋯)×b+c0
Example: Take the number 123(7) (in base 7), and apply the conversion algorithm:
123={1,2,3}N=1N=1∗7+2=9N=9∗7+3=66N=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 or ternary 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) used by Mayan numeral system (and Aztecs)
— base 26 (alphabetic system - base26)
— base 27 (alphabetic system + special character - base27)
— base 36 (alphanumeric system - base36)
— base 37 (alphabetic system + special character - base37)
— 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 "Base N Convert" source code. Except explicit open source licence (indicated Creative Commons / free), the "Base N Convert" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, 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, or API access for "Base N Convert" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.
The copy-paste of the page "Base N Convert" or any of its results, is allowed (even for commercial purposes) as long as you credit dCode!
Exporting results as a .csv or .txt file is free by clicking on the export icon
Cite as source (bibliography):
Base N Convert on dCode.fr [online website], retrieved on 2025-03-26,