Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some simple equations like:

A = (X AND 1779038349) XOR ((X AND 3144134329) XOR 7047511487)

Where A is some constant and X is unknown (all numbers are 32 bit unsigned integers).

How can I solve this for X?

share|cite|improve this question
up vote 3 down vote accepted

As the $x\mapsto x{\,\rm xor\,}s$ is the inverse of itself for all $s$, and that ${\rm and}$ is distributive over ${\rm xor}$, and ${\rm xor}$ is associative, we get

$\begin{align} A{\,\rm xor\,} 7047511487 &= X{\,\rm and\,}(1779038349{\,\rm xor\,}3144134329) \\ A' &= X{\,\rm and\,}3513669172 = X{\,\rm and\,}0b11010001011011100101011000110100 \end{align}$

where $A'$ is another constant ($A'=A{\,\rm xor\,} 7047511487$). So, we get a solution only if the constant $A'$ has no digit $1$ in binary where the right side has $0$ digit, and in that case, on these places $X$ can be arbitrary. In other words, $X$ is masked by the bits of 3513669172 above, and where it contains $0$, $X$ can be arbitrary, when it contains $1$, that digit of $X$ has to be the same as the digit on the same place in $A'$ (from the right).

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.