Is there any XOR bit reduction operand or function in python? I have no problem to write it by yourself, but there’s no reason to write it in every script if there’s already built-in.
r=x&1
for i in xrange(1,63):
r=r^((x>>i)&1)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
this doesn’t answer your question but that code is the same as:
which has the benefit of not depending on the bit length of the number; and is faster (e.g. on
2**62yours takes 46.6 usec and this takes 3.02 usec) because the loop depends on the number of ones (i.e. the population count) in the number not the number of bits.