Skip to content

Commit 9e54101

Browse files
update
1 parent 44fe6c2 commit 9e54101

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

bit_manipulation/count_number_of_one_bits.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
1-
def count_one_bits(number: int) -> int:
1+
def get_set_bits_count(number: int) -> int:
22
"""
3-
Take in an 32 bit integer, count the number of one bits,
4-
return the number of one bits
5-
result of a count_one_bits and operation on the integer provided.
6-
>>> count_one_bits(25)
3+
Count the number of set bits in a 32 bit integer
4+
>>> get_set_bits_count(25)
75
3
8-
>>> count_one_bits(37)
6+
>>> get_set_bits_count(37)
97
3
10-
>>> count_one_bits(21)
8+
>>> get_set_bits_count(21)
119
3
12-
>>> count_one_bits(58)
10+
>>> get_set_bits_count(58)
1311
4
14-
>>> count_one_bits(0)
12+
>>> get_set_bits_count(0)
1513
0
16-
>>> count_one_bits(256)
14+
>>> get_set_bits_count(256)
1715
1
18-
>>> count_one_bits(-1)
16+
>>> get_set_bits_count(-1)
1917
Traceback (most recent call last):
2018
...
2119
ValueError: the value of input must be positive
22-
>>> count_one_bits(1.1)
23-
Traceback (most recent call last):
24-
...
25-
TypeError: Input value must be a 'int' type
26-
>>> count_one_bits("0")
27-
Traceback (most recent call last):
28-
...
29-
TypeError: '<' not supported between instances of 'str' and 'int'
3020
"""
3121
if number < 0:
3222
raise ValueError("the value of input must be positive")
33-
elif isinstance(number, float):
34-
raise TypeError("Input value must be a 'int' type")
35-
elif isinstance(number, str):
36-
raise TypeError("'<' not supported between instances of 'str' and 'int'")
3723
result = 0
3824
while number:
3925
if number % 2 == 1:

0 commit comments

Comments
 (0)