You could always make passes through the bits:
1) AND X and Y together into a different variable (c):
2) Bit shift (c) one bit to the (left/right) depending on your endian. Check for 0 value.
3) XOR X and Y together into another variable (d). If step 2 was a zero value, this is your correct answer.
If step 2 was not a zero value:
4) Repeat 1-3 on (c) and (d).
This is very recursive, and it can't handle numbers which approach the limit of an integer, nor can it handle negative numbers without modification. It's not a perfect solution, but at least it's enough to help you start thinking in terms outside of strict mathematics.