Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded binery_or_operator.py to bit manipulation file #2331
Conversation
TravisBuddy
commented
Aug 18, 2020
Hey @Firejay3, TravisCI finished with status TravisBuddy Request Identifier: 70bb37b0-e137-11ea-a6dd-d374b9ca78b0 |
|
||
def Binary_OR_Operator (a : int, b : int): | ||
|
||
if type(a) == float or type(b) == float: |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 18, 2020
Member
Use isinstance() instead of directly comparing types as discussed in PEP8.
This comment has been minimized.
This comment has been minimized.
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: |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 18, 2020
Member
Why not just use Python builtin https://docs.python.org/3/library/functions.html#bin
This comment has been minimized.
This comment has been minimized.
Firejay3
Aug 18, 2020
Author
Contributor
well i saw the empty file there so i thought it wanted somthing like that?
This comment has been minimized.
This comment has been minimized.
Firejay3
Aug 18, 2020
Author
Contributor
well i can i can remove the extra function for that as well
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 18, 2020
Member
You can leave the function in if you want but just make sure there are doctests which demonstrate that it produces the same results as bin()
for positive ints, zero, negative ints, floats, str, True, and None.
The GItHub Task List above works like this |
TravisBuddy
commented
Aug 18, 2020
Hey @Firejay3, TravisCI finished with status TravisBuddy Request Identifier: e3e03360-e161-11ea-81c3-ef1e647c3fbd |
Co-authored-by: Christian Clauss <cclauss@me.com>
else: | ||
greater = len(b_binary) | ||
a_binary = a_binary.zfill(greater) | ||
for i in range(greater): |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 18, 2020
Member
Nice! So how could we use zip()
https://docs.python.org/3/library/functions.html#zip
for char_a, char_b in zip(a_binary, b_binary):
This comment has been minimized.
This comment has been minimized.
Firejay3
Aug 18, 2020
Author
Contributor
probably just swapping out the for loop for that
for char_a, char_b in zip(a_binary, b_binary):
if char_a == "1" or char_b == "1":
binary.append("1")
else:
binary.append("0")
I'm not entirely sure if there is a simpler way for it or not
TravisBuddy
commented
Aug 18, 2020
Hey @Firejay3, TravisCI finished with status TravisBuddy Request Identifier: 13ca6640-e17b-11ea-81c3-ef1e647c3fbd |
if char_a == "1" or char_b == "1": | ||
binary.append("1") | ||
else: | ||
binary.append("0") |
This comment has been minimized.
This comment has been minimized.
cclauss
Aug 18, 2020
•
Member
if char_a == "1" or char_b == "1": | |
binary.append("1") | |
else: | |
binary.append("0") | |
binary.append(str(int("1" in (char_a, char_b))) |
Firejay3 commentedAug 18, 2020
•
edited
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.