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.

 

Binary:

Ternary:
Quintal:
Octal:
Decimal:
Duodecimal:
Hexadecimal:
Base 36:

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 (N = 2) system there are only two digits: 0 and 1; in the decimal (N = 10) there are ten of them: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. What if N exceeds 10?

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 = akNk + ak-1Nk-1 + ... + a1N1 + a0

with 0 ≤ ai < N we have a representation of M in base N system and write

  M = (akak-1...a0)N

If we rewrite (1) as

(2) M = a0 + N·(a1 + N·(a2 + N·...))

the algorithm for obtaining coefficients ai becomes more obvious. For example, a0 = M (mod N) and a1 = (M/N) (mod N), and so on. (K. Atkinson addresses specifics of the conversion between binary, decimal and hexadecimal systems in his Elementary Numerical Analysis, John Wiley & Sons, 1985.) Elsewhere I explain how to implement this procedure in both recursive and iterative manners.

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

  1. K. Atkinson, Elementary Numerical Analysis, John Wiley & Sons, 1985
  2. W. Dunham, The Mathematical Universe, John Wiley & Sons, 1994
  3. Oystein Ore, Number Theory and Its History, Dover Publications, 1976
  4. J. A. Paulos, Beyond Numeracy, Vintage Books, 1992

Related material
Read more...

  • Expansion of Integers in an Integer Base
  • Base (Binary, Decimal, etc.) Converter
  • Implementation of Base Conversion Algorithms
  • Conversion of Fractions in Various Bases
  • Scoring: the simplest of the impartial games
  • History of the Binary System
  • Calculation of the Digits of pi by the Spigot Algorithm of Rabinowitz and Wagon
  • Addition and Multiplication Tables in Various Bases
  • |Contact| |Front page| |Contents| |Arithmetic| |Algebra| |Store|

    Copyright © 1996-2017 Alexander Bogomolny

     61167321

    Search by google: