Base Converter

This page uses JavaScript. Controls will not work unless you have a JavaScript aware browser. Netscape will do.

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. I still plan to add binary specifics at a later date.

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 equivalent 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 = N*(ak+N*(ak-1+N*...))+a0

the algorithm for obtaining coefficients ai becomes more obvious. For example, a0=M modulo N and a1=(M/N) modulo N, and so on.

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.

Binary:

Ternary:
Quintal:
Octal:
Decimal:
Hexadecimal:

Would you like to have conversions in additional bases?




This page is Netscape enhanced.

Created with Netscape Navigator Gold