Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x % 2^n = x & (2^n - 1), x * 2^n = x << n #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Jun 17, 2018

  1. x % 2^n = x & (2^n - 1), x * 2^n = x << n

    `Shift` is faster than multiplication: x * 2^n = x << n
    Bitwise `and` is faster than division:  x % 2^n = x & (2^n - 1)
    Maybe there is no big speed improvement, but in iterations it makes sense to use the fastest operation available.
    duzun committed Jun 17, 2018
    Configuration menu
    Copy the full SHA
    389d710 View commit details
    Browse the repository at this point in the history