Skip to content

Commit edee8e6

Browse files
use format to remove '0b' (TheAlgorithms#11307)
* use format to remove '0b' * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: error message for float input --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 723cf9c commit edee8e6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bit_manipulation/binary_and_operator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def binary_and(a: int, b: int) -> str:
2626
>>> binary_and(0, 1.1)
2727
Traceback (most recent call last):
2828
...
29-
TypeError: 'float' object cannot be interpreted as an integer
29+
ValueError: Unknown format code 'b' for object of type 'float'
3030
>>> binary_and("0", "1")
3131
Traceback (most recent call last):
3232
...
@@ -35,8 +35,8 @@ def binary_and(a: int, b: int) -> str:
3535
if a < 0 or b < 0:
3636
raise ValueError("the value of both inputs must be positive")
3737

38-
a_binary = str(bin(a))[2:] # remove the leading "0b"
39-
b_binary = str(bin(b))[2:] # remove the leading "0b"
38+
a_binary = format(a, "b")
39+
b_binary = format(b, "b")
4040

4141
max_len = max(len(a_binary), len(b_binary))
4242

0 commit comments

Comments
 (0)