Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Tobias

Tobias Avatar

***
Dedicated Member

182


November 2006
function convertBase(convertFrom, convertTo, convertString){ return parseInt(convertString,convertFrom).toString(convertTo);}

Usage: Use to convert from base 16 to 10, or the other way around. Useful for hex codes, etc.

Example:
var Converted = convertBase(16,10,"ff"); //Converted = "255"
var ConvertedBack = convertBase(10,16,Converted); //ConvertedBack = "ff"
A little open source snippet because not many people I know know about the optional parameters in toString and parseInt.

EDIT: Fixed some typos. :P


Last Edit: Jan 7, 2008 20:39:14 GMT by Tobias
#intj (Mastermind)^

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I knew parseInt's, but not toString's.

(You can post in the OS board by the way. ;))

newBookmarkLockedFalling