|
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.
Last Edit: Jan 7, 2008 20:39:14 GMT by Tobias
|
#intj (Mastermind)^
|
|
|
|
I knew parseInt's, but not toString's. (You can post in the OS board by the way. )
|
|
|
|