I saw the hexidecimal blog and figured, hey, I might as well post the scripts I made. Very simply, you input a string, and it outputs your string converted. Yes, I've seen smaller scripts which do the same thing, but I thought it might be fun to make myself, and hey, it was.
Binary to Decimal
Quote:
//Setup Variablesvar len,total,i,ii;bin=string(argument0)len=string_length(bin)len=8-len//Cleaning the Stringbin=string_digits(bin)for(i=0;i<len;i+=1)bin="0"+bin//Make the Conversiontotal=0;for(i=8;i>0;i-=1){ ii=0 ii=real(string_char_at(bin,i)) ii=ii*power(2,8-i) total+=ii}return total;
Quote:
//Setup Variablesvar orig,total,array;orig=real(argument0)array[8]=false//Finding/Assigning Valuesfor(i=7;i>=0;i-=1){ check=power(2,i) if orig>=check { orig-=check array=true }}//Putting Values in Stringtotal=""for(i=7;i>=0;i-=1){ if array=true total+="1" else total+="0"}dec=argument0return total;
You've been played! *snicker*
Optimize it.
I could probably take out half the variables, skip some if checks, and maybe even use less loop iterations, but hey, it's longer code this way, and so my blog has more content! =D
Stop limiting yourself
Looks good.
Binary to Decimal
Your Binary to Decimal's look very similar to Xot's C-Ator, although yours looks a little more efficient.
C-Ator's use of len could be dropped