I am not sure if I understand the O(logn) solution of this question.
def parity(x):
Let’s say, parity of 8 (or 1000). After the operation in the book that goes splitting the bit into half at every step:
x^=x>>2
what I don’t specifically understand is this part in the book(EPI in python pg 29, 2018 edition) using a similar example with an 8-bit number 11010111, paraphrasing it kind of:
“Note that the first XOR yields 11011010, and only last 4 digits are relevant going forward”.
Why is that? How come only last 4 digits are relevant?
Can some please explain me the logic behind that. Thanks so much in advance.