Whats the reverse function of x XOR (x/2)?
Is there a system of rules for equation solving, similar to algebra, but with logic operators?
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.
Suppose we have a number
xof N bits. You could write this as:where
b(i)is bit numberiin the number (where 0 is the least significant bit).x / 2is the same asxshifted left 1 bit. Let’s assume unsigned numbers. So:Now we XOR
xwithx / 2:Note that the rightmost bit (the most significant bit) of this is
b(N-1)^0which isb(N-1). In other words, you can get bitb(N-1)from the result immediately. When you have this bit, you can calculateb(N-2)because the second bit of the result isb(N-2)^b(N-1)and you already knowb(N-1). And so on, you can compute all bitsb(N-1)tob(0)of the original numberx.