deivy petrescu wrote on Tue, 7 Jun 2005 22:23:36 -0400:
set andit to (reverse of andit) as string
set orit to (reverse of orit) as string
set xorit to (reverse of xorit) as string
return {toand:andit, toor:orit, toxor:xorit}
end andorxorit
Are you sure you mean those reverses, Deivy?
toxor of andorxorit(1110, "1111")
-->"1000"
Well, I meant it but I was wrong! The reverse is wrong
Now, Nigel, my sincerest apologies. How could I've thought of a
script with "script o".
I am truly sorry!
:)
This is a bit faster and can handle bit patterns of unequal length:
on andorxorit(a, b)
script o
property x : a div 1
property y : b div 1
end script
if (a > b) then
set c to a reference to o's x
else
set c to a reference to o's y
end if
set andit to {}
set orit to {}
set xorit to {}
repeat until (c < 1)
set {aj, bj, o's x, o's y} to {(o's x) mod 10, (o's y) mod
10, (o's
x) div 10, (o's y) div 10}
if (aj > 1) or (bj > 1) then
display dialog "no can do!"
return -- something
end if
set sum to (aj + bj) div 1
set beginning of andit to sum div 2
set beginning of orit to (sum + 1) div 2
set beginning of xorit to sum mod 2
end repeat
set andit to andit as string
set orit to orit as string
set xorit to xorit as string
return {toand:andit, toor:orit, toxor:xorit}
end andorxorit
NG
Actually I like your script better than mine. Yyour xorit is
actually good for any numbers of terms.
First question, did you run your script, can you use sum as a variable?
Second, using different lengths is not good. Example "00111" and
"01111" whatever is the operation you want a five digits number which
you will not get with your script. You would get an error message
otherwise.