Created
March 28, 2012 15:16
-
-
Save bassx/2227137 to your computer and use it in GitHub Desktop.
AppleScript Handler: bitwise AND operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* __int1 : integer | |
* __int2 : integer | |
* Integers are from 0 till 2 ^ 31 - 1. When integers become greater than 2 ^ 31 then they will become a real and the handler wont't work. | |
*) | |
on BWAND(__int1, __int2) | |
set theResult to 0 | |
repeat with bitOffset from 30 to 0 by -1 | |
if __int1 div (2 ^ bitOffset) = 1 and __int2 div (2 ^ bitOffset) = 1 then | |
set theResult to theResult + 2 ^ bitOffset | |
end if | |
set __int1 to __int1 mod (2 ^ bitOffset) | |
set __int2 to __int2 mod (2 ^ bitOffset) | |
end repeat | |
return theResult as integer | |
end BWAND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment