Skip to content

Added binery_or_operator.py to bit manipulation file #2331

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

Merged
merged 8 commits into from
Aug 27, 2020
Merged
Changes from 1 commit
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
25 changes: 5 additions & 20 deletions bit_manipulation/binary_or_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

def Binary_OR_Operator (a : int, b : int):

if type(a) == float or type(b) == float:
if isinstance(a, float) or isinstance(b, float):
raise TypeError("'Float' object cannot be implemented as an integer")
if type(a) == str or type(b) == str:
if isinstance(a, str) or isinstance(b,str):
raise TypeError("'str' object cannot be implemented as an integer")
if a <0 or b < 0:
if a < 0 or b < 0:
raise ValueError("the value of both input must be positive")
"""
a_binary and b_binary are the binary of a and b in str format
"""
a_binary = convert_to_binary(a)
b_binary = convert_to_binary(b)
a_binary = str(bin(a))[2:]
b_binary = str(bin(b))[2:]
binary = []
if len(a_binary) > len(b_binary):
greater = len(a_binary)
Expand All @@ -50,21 +50,6 @@ def Binary_OR_Operator (a : int, b : int):
return "0b" + "".join(binary)


"""
The function below converts the integer input from decimal to binary and
returns the binary in str format
"""
def convert_to_binary(num: int)-> str:

first = True
while num > 0:
if first:
binarynumber = str(num%2)
first = False
else:
binarynumber = str(num%2) + binarynumber
num = int(num / 2)
return binarynumber

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