mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-06-06 22:28:49 -04:00
Change the dir structure slightly
This commit is contained in:
parent
6b6fe21db3
commit
2f4a9638c0
184 changed files with 0 additions and 21 deletions
|
@ -1,25 +0,0 @@
|
|||
#!/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()
|
Loading…
Add table
Add a link
Reference in a new issue