Created
March 28, 2012 07:01
-
-
Save Jim-Holmstroem/2224397 to your computer and use it in GitHub Desktop.
int to list of bits in Python
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 int2bits(i,n,zero_element=0,one_element=1): | |
return list((zero_element,one_element)[i>>j & 1] for j in xrange(n-1,-1,-1)) | |
for i in range(16): | |
print int2bits(i,4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment