mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Fix type annotations for bit manipulation algorithms (#4056)
This commit is contained in:
parent
f3ba9b6c50
commit
8f47d9f807
|
@ -1,7 +1,7 @@
|
||||||
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||||
|
|
||||||
|
|
||||||
def binary_and(a: int, b: int):
|
def binary_and(a: int, b: int) -> str:
|
||||||
"""
|
"""
|
||||||
Take in 2 integers, convert them to binary,
|
Take in 2 integers, convert them to binary,
|
||||||
return a binary number that is the
|
return a binary number that is the
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||||
|
|
||||||
|
|
||||||
def binary_or(a: int, b: int):
|
def binary_or(a: int, b: int) -> str:
|
||||||
"""
|
"""
|
||||||
Take in 2 integers, convert them to binary, and return a binary number that is the
|
Take in 2 integers, convert them to binary, and return a binary number that is the
|
||||||
result of a binary or operation on the integers provided.
|
result of a binary or operation on the integers provided.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
# https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||||
|
|
||||||
|
|
||||||
def binary_xor(a: int, b: int):
|
def binary_xor(a: int, b: int) -> str:
|
||||||
"""
|
"""
|
||||||
Take in 2 integers, convert them to binary,
|
Take in 2 integers, convert them to binary,
|
||||||
return a binary number that is the
|
return a binary number that is the
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"""Provide the functionality to manipulate a single bit."""
|
"""Provide the functionality to manipulate a single bit."""
|
||||||
|
|
||||||
|
|
||||||
def set_bit(number: int, position: int):
|
def set_bit(number: int, position: int) -> int:
|
||||||
"""
|
"""
|
||||||
Set the bit at position to 1.
|
Set the bit at position to 1.
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ def set_bit(number: int, position: int):
|
||||||
return number | (1 << position)
|
return number | (1 << position)
|
||||||
|
|
||||||
|
|
||||||
def clear_bit(number: int, position: int):
|
def clear_bit(number: int, position: int) -> int:
|
||||||
"""
|
"""
|
||||||
Set the bit at position to 0.
|
Set the bit at position to 0.
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ def clear_bit(number: int, position: int):
|
||||||
return number & ~(1 << position)
|
return number & ~(1 << position)
|
||||||
|
|
||||||
|
|
||||||
def flip_bit(number: int, position: int):
|
def flip_bit(number: int, position: int) -> int:
|
||||||
"""
|
"""
|
||||||
Flip the bit at position.
|
Flip the bit at position.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user