Skip to content
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

Added binery_or_operator.py to bit manipulation file #2331

Merged
merged 8 commits into from Aug 27, 2020

Conversation

@Firejay3
Copy link
Contributor

Firejay3 commented Aug 18, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Firejay3 added 2 commits Aug 18, 2020
@TravisBuddy
Copy link

TravisBuddy commented Aug 18, 2020

Hey @Firejay3,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

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.

@cclauss

cclauss Aug 18, 2020

Member

Use isinstance() instead of directly comparing types as discussed in PEP8.

This comment has been minimized.

@Firejay3

Firejay3 Aug 18, 2020

Author Contributor

alright noted, thanks

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.

@Firejay3

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.

@Firejay3

Firejay3 Aug 18, 2020

Author Contributor

well i can i can remove the extra function for that as well

This comment has been minimized.

@cclauss

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.

@cclauss
Copy link
Member

cclauss commented Aug 18, 2020

@TravisBuddy
Copy link

TravisBuddy commented Aug 18, 2020

Hey @Firejay3,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

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.

@cclauss

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.

@Firejay3

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
Copy link

TravisBuddy commented Aug 18, 2020

Hey @Firejay3,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 13ca6640-e17b-11ea-81c3-ef1e647c3fbd
if char_a == "1" or char_b == "1":
binary.append("1")
else:
binary.append("0")
Comment on lines 39 to 42

This comment has been minimized.

@cclauss

cclauss Aug 18, 2020

Member
Suggested change
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)))

This comment has been minimized.

@Firejay3

Firejay3 Aug 18, 2020

Author Contributor

owh... noted. Thank you very much

Firejay3 and others added 2 commits Aug 18, 2020
@cclauss cclauss merged commit 61dde44 into TheAlgorithms:master Aug 27, 2020
2 checks passed
2 checks passed
codespell
Details
Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.