Skip to content

Commit

Permalink
use format to remove '0b' (TheAlgorithms#11307)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
groupsvkg and pre-commit-ci[bot] authored Jun 2, 2024
1 parent 723cf9c commit edee8e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bit_manipulation/binary_and_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def binary_and(a: int, b: int) -> str:
>>> binary_and(0, 1.1)
Traceback (most recent call last):
...
TypeError: 'float' object cannot be interpreted as an integer
ValueError: Unknown format code 'b' for object of type 'float'
>>> binary_and("0", "1")
Traceback (most recent call last):
...
Expand All @@ -35,8 +35,8 @@ def binary_and(a: int, b: int) -> str:
if a < 0 or b < 0:
raise ValueError("the value of both inputs must be positive")

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

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

Expand Down

0 comments on commit edee8e6

Please sign in to comment.