Hi,
Is there a simple function or code to convert decimals to binary and vice versa?
thanks in advance,
Izak
Is there a simple function or code to convert decimals to binary and vice versa?
thanks in advance,
Izak
/*******************************************************
CONVERSIONS
By Ryan Parman
Distributed according to SkyGPL 2.1, [url]http://www.skyzyx.com/license/[/url]
*******************************************************/
function preMain() {
setStudyTitle("Number Converter");
setShowCursorLabel(false);
}
function main() {
if (getCurrentBarIndex() == -1) {
var num = new decimal(181).toBinary();
debugPrintln("181 to binary = " + num);
debugPrintln(num + " to decimal = " + new binary(num).toDecimal());
}
return;
}
function decimal(dec)
{
this.dec=dec;
this.toBinary=function() { return this.dec.toString(2); }
this.toHex=function() { return this.dec.toString(16).toUpperCase(); }
this.toOctal=function() { return this.dec.toString(8); }
}
function binary(bin)
{
this.bin=bin;
this.toDecimal=function() { return parseInt(this.bin, 2); }
this.toHex=function() { return this.toDecimal().toString(16).toUpperCase(); }
this.toOctal=function() { return this.toDecimal().toString(8); }
}
function hex(hex)
{
this.hex=hex;
this.toDecimal=function() { return parseInt(this.hex, 16); }
this.toBinary=function() { return this.toDecimal().toString(2); }
this.toOctal=function() { return this.toDecimal().toString(8); }
}
function octal(oct)
{
this.oct=oct;
this.toDecimal=function() { return parseInt(this.oct, 8); }
this.toBinary=function() { return this.toDecimal().toString(2); }
this.toHex=function() { return this.toDecimal().toString(16).toUpperCase(); }
}
Comment