Skip to content

Instantly share code, notes, and snippets.

@JoshuaChi
Created December 18, 2013 09:27
Show Gist options
  • Save JoshuaChi/8019607 to your computer and use it in GitHub Desktop.
Save JoshuaChi/8019607 to your computer and use it in GitHub Desktop.
def bits(n):
    while n:
        b = n & (~n+1)
        yield b
        n ^= b
>>> for b in bits(109):
    print(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment