Re: Binary math operations (and, or, etc.)
Re: Binary math operations (and, or, etc.)
- Subject: Re: Binary math operations (and, or, etc.)
- From: deivy petrescu <email@hidden>
- Date: Tue, 7 Jun 2005 22:23:36 -0400
On Jun 7, 2005, at 21:13, Stephen Jonke wrote:
Is binary math (meaning OR, XOR, AND, etc) built in to Applescript?
Not logical, mathematical. The obvious syntax doesn't work. Am I
just missing it?
Steve
_________________________________________________________________
Stephen Jonke email@hidden
Is this what you want :
<script>
toxor of andorxorit(1110, "0111")
--->"1001"
on andorxorit(a, b)
set {a, b} to {characters of (a as string), characters of (b as
string)}
if length of a ≠ length of b then
display dialog "no can do!"
return
end if
set andit to {}
set orit to {}
set xorit to {}
repeat with j from 1 to (length of b)
set {aj, bj} to {(item j of a), (item j of b)}
if aj is not in {"0", "1"} or bj is not in {"0", "1"} then
display dialog "no can do!"
return
end if
if aj + bj = 2 then
set end of andit to "1"
set end of orit to "1"
set end of xorit to "0"
else if aj + bj = 1 then
set end of andit to "0"
set end of orit to "1"
set end of xorit to "1"
else
set end of andit to "0"
set end of orit to "0"
set end of xorit to "0"
end if
end repeat
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
</script>
You can sophisticate the code yourself, I do not know if you want it
for IP purposes or what.
Tweak as much as you want
deivy petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden