Added binary_xor_operator.py and binary_and_operator.py#2433
Added binary_xor_operator.py and binary_and_operator.py#2433cclauss merged 4 commits intoTheAlgorithms:masterfrom vivek9patel:master
Conversation
Travis tests have failedHey @vivek9patel, TravisBuddy Request Identifier: d0978fe0-f766-11ea-bb1a-aff04add7ab5 |
|
@cclauss can you please review this? |
| if a < 0 or b < 0: | ||
| raise ValueError("the value of both input must be positive") | ||
|
|
||
| a_binary = str(bin(a))[2:] # remove the leading "0b" |
There was a problem hiding this comment.
why not just use
def binary_xor(a: int, b: int):
xor = a ^ b
return bin(xor)
would not it be faster or not?
and I don't understand why xor operators binary representation in your result differ than core xor operator:
for inputs:
37 ^ 50 = 0b10111
but in your version:
37 ^ 50 = 0b010111
yes of course you would be right if you say that leading zeros would not change the value but I think it would be better if we remove leading zeros after 0b ?
it's just my opinion, maybe @cclauss and others are agree with your version.
There was a problem hiding this comment.
Often in this repo we are trying to demonstrate how an algorithm works. Our primary goal is education not always optimized performance. If we just use Python's builtin capabilities and its standard library we can often write code in a line or two but we lose a lot of educational value. Often the one or two-liner is great to use in our doctests to prove that the educational long-form gives the same results as the builtin short-form over a range of test values.
There was a problem hiding this comment.
The first thing using a^b gives us decimal representation on xor value
this function gives us a binary representation of xor function.
Totally agree with @cclauss ,this is just for learning and practicing things!
There was a problem hiding this comment.
Often in this repo we are trying to demonstrate how an algorithm works. Our primary goal is education not always optimized performance. If we just use Python's builtin capabilities and its standard library we can often write code in a line or two but we lose a lot of educational value. Often the one or two-liner is great to use in our doctests to prove that the educational long-form gives the same results as the builtin short-form over a range of test values.
But one more thing @cclauss does my PR is having any problems, because it is one week and it is not reviewed yet!?
There was a problem hiding this comment.
@cclauss ok, understand, thank you for your clarification
…s#2433) * Added binary_and_operator.py & binary_xor_operator.py * Updated binary_and_operator.py * Updated binary_xor_operator.py * Updated binary_xor_operator.py
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.