Difference between revisions of "Base2Dec"

From Second Life Wiki
Jump to navigation Jump to search
(Created page)
 
m (<lsl> tag to <source>)
 
Line 3: Line 3:
This function converts a number to decimal from any base (up to 16). Its parameters are the number to be converted, and the base to convert from.
This function converts a number to decimal from any base (up to 16). Its parameters are the number to be converted, and the base to convert from.


<lsl>
<source lang="lsl2">
integer sbBase2Dec(string strNumber, integer intBase) {
integer sbBase2Dec(string strNumber, integer intBase) {
     string  strDigits = "0123456789abcdef";
     string  strDigits = "0123456789abcdef";
Line 13: Line 13:
     return intReturn;
     return intReturn;
}
}
</lsl>
</source>


{{LSLC|Library}}{{LSLC|Examples}}
{{LSLC|Library}}{{LSLC|Examples}}

Latest revision as of 14:06, 24 January 2015

This function converts a number to decimal from any base (up to 16). Its parameters are the number to be converted, and the base to convert from.

integer sbBase2Dec(string strNumber, integer intBase) {
    string  strDigits = "0123456789abcdef";
    integer intDigit  = -llStringLength(strNumber);
    integer intReturn = 0;

    while(intDigit)
        intReturn = (intReturn * intBase) + llSubStringIndex(strDigits, llGetSubString(strNumber, intDigit, intDigit++));
    return intReturn;
}