Last active
December 2, 2017 07:27
-
-
Save SteadBytes/265d5d752679d76fadad3a49f1791db4 to your computer and use it in GitHub Desktop.
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
def split_power_2(x): | |
""" Splits a number up into powers of 2, returning a list of powers. | |
""" | |
split_powers = [] | |
i = 1 | |
while i <= x: | |
if i & x: # 1 or 0 -> evaluate as True/False | |
split_powers.append(i) | |
i <<= 1 | |
return split_powers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment