JavaScript Int to Hex converter and Universal base converter!

JavaScript Integer to Hex Converter

A simple Hex to Integer converter that I wrote using JavaScript.

Int -> Hex:
Hex -> Int:

JavaScript universal base converter!

I thought I'd have some fun and create a universal converter

From base:
To base:
Base 10 -> 2:
Base 2 -> 10:

This code is pretty simple. Here's the main function:

  1. function baseToBase (fromBase, toBase, value) {;
  2. if(value=="")
  3. value = 0;
  4. value = parseInt(value, fromBase);
  5. return Number(value).toString(toBase).toUpperCase();
  6. }

It just uses JavaScript's parse int to convert the from field into a decimal. Then it uses the toString method to covert this decimal to the correct base. The rest of the code (which can be seen by looking at the source) is just involves some jQuery calls to get the boxes working together.

Tweet: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.