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

Conversation

Firejay3
Copy link
Contributor

@Firejay3 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}.

@TravisBuddy
Copy link

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i saw the empty file there so i thought it wanted somthing like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

The GItHub Task List above works like this
https://docs.github.com/en/github/managing-your-work-on-github/about-task-lists

@TravisBuddy
Copy link

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

else:
greater = len(b_binary)
a_binary = a_binary.zfill(greater)
for i in range(greater):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Comment on lines 39 to 42
if char_a == "1" or char_b == "1":
binary.append("1")
else:
binary.append("0")
Copy link
Member

@cclauss cclauss Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

owh... noted. Thank you very much

@cclauss cclauss merged commit 61dde44 into TheAlgorithms:master Aug 27, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
)

* added bitwise binary OR operator

* Rename binary_OR_operator.py to binary_or_operator.py

* Update binary_or_operator.py

* Update binary_or_operator.py

* Update bit_manipulation/binary_or_operator.py

Co-authored-by: Christian Clauss <[email protected]>

* Update binary_or_operator.py

* Update binary_or_operator.py

* Nice!!

Co-authored-by: Christian Clauss <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants