cleaning up and organizing old problems (builtin)

This commit is contained in:
Mari Wahl 2015-01-06 20:10:48 -05:00
parent 6afe96fa4d
commit 3fdbc2a605
106 changed files with 480 additions and 1472 deletions

25
src/bitwise/find_bit_len.py Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env python
__author__ = "bt3"
''' Find how many bits a int has:
1) Start with a mask of 1
2) Mask with AND
3) if result (if true): count += 1
(obs: to find the int of a bin do int('1001', 2)) and to show in bin do bin(int))
'''
def find_bit_len(int_num):
lenght = 0
while int_num:
int_num >>= 1
lenght += 1
return lenght
if __name__ == '__main__':
for i in range(17):
print(find_bit_len(i))
print i.bit_length()
print