Difference between revisions of "BinaryDecimalConverter"
Jump to navigation
Jump to search
Line 19: | Line 19: | ||
<lsl> | <lsl> | ||
string | string decToBin(integer val) | ||
{ | { | ||
string binary; | string binary; |
Revision as of 05:34, 18 October 2009
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
The next function converts a binary value to a decimal number. Works +/- 5 times faster than Base2Dec : <lsl> integer binToDec(string val) {
integer dec; integer i = -llStringLength(val); while(++i < 0) { dec = (dec << 1) + (integer)llGetSubString(val, i, i); } return dec;
} </lsl>
This one converts a decimal to a binary value:
<lsl> string decToBin(integer val) {
string binary; integer i = val; while (i) { if (i % 2) binary = "1" + binary; else binary = "0" + binary; i = i >> 1; } return binary;
} </lsl>
Greets from Soundless :)