You are viewing a single comment's thread. Return to all comments →
**Python 3 **
We have int.bit_length to calculate number of digits in binary and int.bit_count to calculate number of ones. So we can solve this pretty easily.
int.bit_length
int.bit_count
def sumXor(n): return 2 ** (n.bit_length() - n.bit_count())
Seems like cookies are disabled on this browser, please enable them to open this website
Sum vs XOR
You are viewing a single comment's thread. Return to all comments →
**Python 3 **
We have
int.bit_length
to calculate number of digits in binary andint.bit_count
to calculate number of ones. So we can solve this pretty easily.