play and relax: games for kids games
  Cut the knot: learn to enjoy mathematics
A math books store at a unique math study site. Learn to enjoy mathematics.
Google
Web CTK
Try our no ads browsing

Best sites for teachers
Sites for teachers
Sites for parents
Terms of use
Awards

Interactive Activities
CTK Exchange
CTK Insights - a blog

Games & Puzzles
What Is What
Arithmetic/Algebra
Geometry
Probability
Outline Mathematics
Make an Identity
Book Reviews
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
Best sites for teachers
Sites for teachers
Sites for parents

Education & Parenting

Manifesto: what CTK is about Buying a book is a commitment to learning Table of content Try our no ads browsing Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

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.

Returning to the converter, for now, you can enter a number in any system. Then just click anywhere outside the edit control box used to input the number. Its representation in other systems will appear in the corresponding text boxes.

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. I am looking into this matter. For now, 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 converter works this way: first type a number in the base you wish to convert from. Then click in any other input box.)

 

 

Binary:

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

Would you like to have conversions in additional bases?

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-2008 Alexander Bogomolny

29704867Page copy protected against web site content infringement by Copyscape


Search:
Keywords:


Latest on CTK Exchange
try this puzzle ?/?? + ?/?? + ?/? ...
Posted by albert1950
2 messages
03:40 PM, Aug-26-08

Numbers raised to the power of 0
Posted by Chris Tolley
20 messages
12:17 PM, Aug-25-08

Arbelos : 1) Geometrical Construc ...
Posted by Sundar Krishnan
12 messages
06:29 AM, Aug-12-08

concerning pi
Posted by Lloyd Marks
4 messages
08:25 AM, Aug-22-08

Triangles With Equal Area
Posted by Bui Quang Tuan
5 messages
07:20 PM, Aug-26-08

Coxeter Introduction to Geometry
Posted by WiZaRd
1 messages
09:15 AM, Aug-23-08

site questions
Posted by madisonv
2 messages
04:24 PM, Aug-26-08