From a950901d5ebaa9e99a7e21fbbbf417366d1d2504 Mon Sep 17 00:00:00 2001 From: Vishal Kumar Gupta Date: Sun, 25 Feb 2024 19:59:24 +0000 Subject: [PATCH 1/3] use format to remove '0b' --- bit_manipulation/binary_and_operator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bit_manipulation/binary_and_operator.py b/bit_manipulation/binary_and_operator.py index 36f6c668d9b3..11a9f65f789a 100644 --- a/bit_manipulation/binary_and_operator.py +++ b/bit_manipulation/binary_and_operator.py @@ -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)) From d39f1b5461ff40e363b2dcb9e51973e241ae0ed4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 25 Feb 2024 20:03:44 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bit_manipulation/binary_and_operator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bit_manipulation/binary_and_operator.py b/bit_manipulation/binary_and_operator.py index 11a9f65f789a..10ba3774dc03 100644 --- a/bit_manipulation/binary_and_operator.py +++ b/bit_manipulation/binary_and_operator.py @@ -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 = format(a, 'b') - b_binary = format(b, 'b') + a_binary = format(a, "b") + b_binary = format(b, "b") max_len = max(len(a_binary), len(b_binary)) From b197d71de9f550d60bfaba90e9a9563303eaf421 Mon Sep 17 00:00:00 2001 From: Vishal Kumar Gupta Date: Sun, 25 Feb 2024 20:28:58 +0000 Subject: [PATCH 3/3] fix: error message for float input --- bit_manipulation/binary_and_operator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bit_manipulation/binary_and_operator.py b/bit_manipulation/binary_and_operator.py index 11a9f65f789a..69e25bab9bae 100644 --- a/bit_manipulation/binary_and_operator.py +++ b/bit_manipulation/binary_and_operator.py @@ -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): ...