Scripting a text to binary digits converter

gpb01 guglielmo at braguglia.ch
Mon Jan 2 16:03:08 EST 2012


Bryan McCormick wrote
> 
> JB, Guglielmo
> 
> This appears to work for my purposes and is pretty speedy. See anything 
> that might break?
> 
> ---------------------------------------
> 
> function convertTextToBinary varText
>     repeat with n = 1 to the number of chars of varText
>        put chartonum(char n of varText) into theNum
>        if theNum >=64 and theNum <= 127 then
>           put "0"&baseConvert(theNum,10,2) after tConverted
>        else if theNum <="64" then
>           put "00"&baseConvert(theNum,10,2) after tConverted
>        else
>           put baseConvert(theNum,10,2) after tConverted
>        end if
>     end repeat
>     return tConverted
> end convertTextToBinary
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at .runrev
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 

Just for fun I tried with a small script you function :
   put convertTextToBinary(theText) into field "outField"

... and the binaryDecode :
   put binaryDecode("B*", theText, binText) into numItems
   put binText into field "outFieldBin"

both inserted in two separate "repeat" to repeat the same statements 200
times, storing the millisecond to execute.

Whit your function, on my Win 7 64 bit system, I have between 60 and 70
milliseconds, with the binaryDecode() + the put statemet (/... two separate
statements/) I have between 20 and 30 milliseconds  :)

So .. the Livecode binaryDecode + the put statement is minimum *TWO* time
faster than calling your function  ;)

Guglielmo



--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Scripting-a-text-to-binary-digits-converter-tp4254413p4254500.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list