Skip to content

Instantly share code, notes, and snippets.

@akulakov
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akulakov/b6e20ee0ed81c06883e4 to your computer and use it in GitHub Desktop.
Save akulakov/b6e20ee0ed81c06883e4 to your computer and use it in GitHub Desktop.
bitwise and Ehtesh
# 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