Scripting a text to binary digits converter
Phil Davis
revdev at pdslabs.net
Mon Jan 2 17:15:24 EST 2012
I tried using the numberFormat to pad zeroes. It worked but was about 20% slower
(if I did my math correctly).
I got roughly a 6% speed improvement using 'repeat for each char tChar' instead
of repeat with n = 1..."
My test sample was 1000 chars.
function convertTextToBinary varText
--repeat with n = 1 to the number of chars of varText
repeat for each char tChar in varText
--put chartonum(char n of varText) into theNum
put chartonum(tChar) into theNum
put baseConvert(theNum,10,2) into tBaseConverted
put char -8 to -1 of ("00000000" & tBaseConverted ) into tBaseConverted
put tBaseConverted after tConverted
end repeat
return tConverted
end convertTextToBinary
Phil Davis
On 1/2/12 1:33 PM, Bryan McCormick wrote:
> JB, Jim, Guglielmo
>
> Okay, this is the final version of the script which does seem considerably
> faster than where I started.
>
> Thanks to all. Hope this was a useful walk-through.
>
> Any other suggestions on ways to improve?
>
> ---------------------------------------------
>
> function convertTextToBinary varText
> repeat with n = 1 to the number of chars of varText
> put chartonum(char n of varText) into theNum
> put baseConvert(theNum,10,2) into tBaseConverted
> put char -8 to -1 of ("00000000" & tBaseConverted ) into tBaseConverted
> put tBaseConverted after tConverted
> end repeat
> return tConverted
> end convertTextToBinary
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list