Skip to content

Instantly share code, notes, and snippets.

@mkolod
Created June 2, 2020 00:01
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 mkolod/c7c7dae10b92d3725d999ae131944270 to your computer and use it in GitHub Desktop.
Save mkolod/c7c7dae10b92d3725d999ae131944270 to your computer and use it in GitHub Desktop.
# precondition: d is power of 2
def mod_pow2(n, d):
return ( n & (d-1) )
print(n, "mod" , d , "is", mod_pow2(6, 4))
@mkolod
Copy link
Author

mkolod commented Jun 2, 2020

Output:

6 mod 4 is 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment