User:Abstract Alchemi: Difference between revisions
Jump to navigation
Jump to search
Created page with '{{skills |Architect= |Builder=* |Machinima= |Scenographer= |Scripter=* |SLogistician= |Terraformer= |}}' |
I wanted to post my script here, and expand on it later, and possiably post it in the LSL Portal when I get it more developed, but for now it goes here! |
||
| Line 1: | Line 1: | ||
==Scripts== | |||
Out of some interest in [http://en.wikipedia.org/wiki/Base_(mathematics) Bases], I wanted to make something that could convert from [http://en.wikipedia.org/wiki/Decimal Base-10] to any other bases. I started off reading documentation on how to do so, and I decided i'd try just to convert from Base-23 to [http://en.wikipedia.org/wiki/Decimal Base-10]. Here are my results! | |||
==Base-23 and [http://en.wikipedia.org/wiki/Decimal Base-10]== | |||
<lsl> | |||
string IntegerToBase23(integer int){ | |||
string code = "0123456789ABCDEFGHIJKLMNOPQRSTUVW"; | |||
string base23; | |||
if(int < 23) return llGetSubString(code,int-1,int-1); | |||
while(int > 23){ | |||
integer mod = int%23; | |||
int = int/23; | |||
base23 += llGetSubString(code,mod,mod); | |||
} | |||
if(int != 0) base23 += llGetSubString(code,int,int); string str; integer i; | |||
for(i = llStringLength(base23)-1; i >= 0; i--) str += llGetSubString(base23,i,i); | |||
return str; | |||
} | |||
integer Base23ToInteger(string src){ | |||
integer base23; integer i; | |||
string code = "0123456789ABCDEFGHIJKLMNOPQRSTUVW"; | |||
for(i = 0; i < llStringLength(src);i++){ | |||
if(llSubStringIndex(code,llGetSubString(src,i,i)) == -1) return -1; | |||
base23 += llSubStringIndex(code,llGetSubString(src,i,i))*(integer)llPow(23,llAbs(i-llStringLength(src)+1)); | |||
} | |||
return base23; | |||
} | |||
default{ | |||
state_entry(){ | |||
integer num = 10; | |||
llSay(0,(string)IntegerToBase23(num)+" == "+(string)Base23ToInteger(IntegerToBase23(num))); | |||
} | |||
} | |||
</lsl> | |||
{{skills | {{skills | ||
|Architect= | |Architect= | ||
Revision as of 21:24, 21 January 2010
Scripts
Out of some interest in Bases, I wanted to make something that could convert from Base-10 to any other bases. I started off reading documentation on how to do so, and I decided i'd try just to convert from Base-23 to Base-10. Here are my results!
Base-23 and Base-10
<lsl> string IntegerToBase23(integer int){
string code = "0123456789ABCDEFGHIJKLMNOPQRSTUVW";
string base23;
if(int < 23) return llGetSubString(code,int-1,int-1);
while(int > 23){
integer mod = int%23;
int = int/23;
base23 += llGetSubString(code,mod,mod);
}
if(int != 0) base23 += llGetSubString(code,int,int); string str; integer i;
for(i = llStringLength(base23)-1; i >= 0; i--) str += llGetSubString(base23,i,i);
return str;
} integer Base23ToInteger(string src){
integer base23; integer i;
string code = "0123456789ABCDEFGHIJKLMNOPQRSTUVW";
for(i = 0; i < llStringLength(src);i++){
if(llSubStringIndex(code,llGetSubString(src,i,i)) == -1) return -1;
base23 += llSubStringIndex(code,llGetSubString(src,i,i))*(integer)llPow(23,llAbs(i-llStringLength(src)+1));
}
return base23;
}
default{
state_entry(){
integer num = 10;
llSay(0,(string)IntegerToBase23(num)+" == "+(string)Base23ToInteger(IntegerToBase23(num)));
}
} </lsl>