Skip to content

changes #12465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

changes #12465

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]

}
42 changes: 1 addition & 41 deletions bit_manipulation/binary_and_operator.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm


def binary_and(a: int, b: int) -> str:
"""
Take in 2 integers, convert them to binary,
return a binary number that is the
result of a binary and operation on the integers provided.

>>> binary_and(25, 32)
'0b000000'
>>> binary_and(37, 50)
'0b100000'
>>> binary_and(21, 30)
'0b10100'
>>> binary_and(58, 73)
'0b0001000'
>>> binary_and(0, 255)
'0b00000000'
>>> binary_and(256, 256)
'0b100000000'
>>> binary_and(0, -1)
Traceback (most recent call last):
...
ValueError: the value of both inputs must be positive
>>> binary_and(0, 1.1)
Traceback (most recent call last):
...
ValueError: Unknown format code 'b' for object of type 'float'
>>> binary_and("0", "1")
Traceback (most recent call last):
...
TypeError: '<' not supported between instances of 'str' and 'int'
"""
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")

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

return "0b" + "".join(
str(int(char_a == "1" and char_b == "1"))
== "1" and char_b == "1"))

Check failure on line 4 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:4:1: SyntaxError: Expected a statement

Check failure on line 4 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:4:25: SyntaxError: Expected a statement

Check failure on line 4 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:4:26: SyntaxError: Expected a statement
for char_a, char_b in zip(a_binary.zfill(max_len), b_binary.zfill(max_len))

Check failure on line 5 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:4:27: SyntaxError: Expected a statement

Check failure on line 5 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:5:1: SyntaxError: Unexpected indentation
)

Check failure on line 6 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:5:84: SyntaxError: Expected ':', found newline

Check failure on line 6 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:6:1: SyntaxError: unindent does not match any outer indentation level

Check failure on line 6 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:6:5: SyntaxError: Expected a statement

Check failure on line 7 in bit_manipulation/binary_and_operator.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff

bit_manipulation/binary_and_operator.py:6:6: SyntaxError: Expected a statement

if __name__ == "__main__":
import doctest
Expand Down
Loading