A math books store at a unique math study site. Shopping at the store helps maintain the site. Thank you.
Learning Math Online
Sites for parents
Terms of use
Awards
Interactive Activities

CTK Exchange
CTK Wiki Math
CTK Insights - a blog
Math Help

III Millennium Olympiad

Games & Puzzles
What Is What
Arithmetic
Algebra
Geometry
Probability
Outline Mathematics
Make an Identity
Book Reviews
Stories for Young
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
Visual Illusions
My Logo
Math Poll
Cut The Knot!
MSET99 Talk
Other Math sites
Front Page
Movie shortcuts
Personal info
Privacy Policy

Guest book
News sites

Recommend this site

Sites for parents

Education & Parenting

Manifesto  |  Bookstore  |  Contents  |  Amazon store  |  Term index  |  What changed?  |  Contact  |  Recommend
RSS Feed: Recent changes at CTK

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

I began planning this page as an introduction into binary systems. As the first step, I applied JavaScript to create a converter between the binary and decimal systems. But what do you know? It was easier and more natural to write a generic base converter than doing anything special for the binary system. JavaScript is really fantastic. I am looking forward to trying Java as well. Then this is what came out of my first attempt to create a binary converter. It is a more or less general converter between representations of the same number in various base system. Please note that the number of digits in any base (radix) N is exactly the same number N. For example, in the binary (N = 2) system there are 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.

(The converter works this way: first type a number in the base you wish to convert from. Then click in any other text box or press Enter. The representations in other systems will appear in the corresponding text boxes. Also note that a newer version of the Base Converter handles also fractions and mixed numbers.)

 

Binary:

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

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

Copyright © 1996-2010 Alexander Bogomolny

35584844Page copy protected against web site content infringement by Copyscape

Search:
Keywords:

Google
Web CTK