Last active
August 29, 2015 14:07
-
-
Save akulakov/b6e20ee0ed81c06883e4 to your computer and use it in GitHub Desktop.
bitwise and Ehtesh
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
# allowed operators: | |
# - recursion | |
# - shift | |
# - add | |
# - mul | |
# - div | |
# - mod | |
def bitwise_and_1(a, b): | |
result = 0 | |
index = 0 | |
while a > 0 and b > 0: | |
r = int((a % 2) == (b % 2) == 1) | |
result += r << index | |
a = a >> 1 | |
b = b >> 1 | |
index += 1 | |
return result | |
print(bitwise_and_1(127,127)) | |
#bitwise_and(127,127) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment