Base Converter
A German merchant of the fifteenth century asked an eminent professor where he should send his son for a good business education. The professor responded that German universities would be sufficient to teach the boy addition and subtraction but he would have to go to Italy to learn multiplication and division. Before you smile indulgently, try multiplying or even just adding the Roman numerals CCLXIV, MDCCCIX, DCL, and MLXXXI without first translating them.
John Allen Paulos, Beyond Numeracy |
The device below converts between 8 different bases. Another device permits the user to specify the bases of conversion.
Input a number in any base and, to see the conversion, click on any other input control.
Please note that the number of digits in any base (also called radix) N is exactly the same number N. For example, in the binary
If N > 10, the missing digits come from the alphabet (usually disregarding the case.) Thus A stands for the decimal 10 in any number system with base greater than 10. B stands for the decimal 11 in any number system with base greater than 11, and so on. Here is the list of hexadecimal (base 16) digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
It is customary to prefix hexadecimal numbers with 0x and octals with 0. The converter will accept this common notation which is, however, not necessary.
Please note the following. Representation of a number in a system with base (radix) N may only consist of digits that are smaller than N.
More accurately, if
(1) | M = a_{k}N^{k} + a_{k-1}N^{k-1} + ... + a_{1}N^{1} + a_{0} |
with 0 ≤ a_{i} < N we have a representation of M in base N system and write
M = (a_{k}a_{k-1}...a_{0})_{N} |
If we rewrite (1) as
(2) | M = a_{0} + N·(a_{1} + N·(a_{2} + N·...)) |
the algorithm for obtaining coefficients a_{i} becomes more obvious. For example,
Here, at one stage of conversion I use a built-in function parseInt which does not seem to return whenever this condition is violated by the very first digit. This appears to be a bug in the parseInt function. Please follow the rule:
Representation of a number in a system with base (radix) N may only consist of digits that are less than N.
The books below, as most others, describe how to convert between various systems but seldom address the question of arithmetic operations in different bases. ([Atkinson] demonstrates how addition and multiplication work in the binary system.) The reason is it's all about the same. Once you know how to do that in the decimal system, you are supposed to know how to handle the same thing in other bases. However, this logic has little appeal to most of us. So I have put together a page devoted exclusively to the Arithmetic Operations in Various Bases.
References
- K. Atkinson, Elementary Numerical Analysis, John Wiley & Sons, 1985
- W. Dunham, The Mathematical Universe, John Wiley & Sons, 1994
- Oystein Ore, Number Theory and Its History, Dover Publications, 1976
- J. A. Paulos, Beyond Numeracy, Vintage Books, 1992
|Contact| |Front page| |Contents| |Arithmetic| |Algebra|
Copyright © 1996-2018 Alexander Bogomolny66985570