XOR expression

Hello,
I have an expression:
 
X = X ^ ( (X >> 2) + (X << 5) + Y );

I'd like to know how to express Y, and how to get Y after we calculated X.
Last edited on
What do you mean "express Y"?

You can simply do a cout of Y. Y is not changed by your expression.
 
cout << "Y=" << Y << endl;

With word express I mean following:
2 + Y = 5
Y Expression is:
Y = 5 - 2

I want to express Y because I don't know it..
Last edited on
So, generalised, you want to get ther value of c from the equation
a=((long long)(b+((b/4)+(b*32)+c))%(long long)pow(2.0, 32)*
Right?
*right-shifiting by x is the divizion by 2x, left-shifting my x is multiplying by 2x and xoring is addition with modulo the number of compinations with that data type.
Yes
Oh wait, it's acutaly adition with modulo for each bit... oh nvm
original:
X = X ^ ( (X >> 2) + (X << 5) + Y );

XOR each side with X:
0 = (X >> 2) + (X << 5) + Y;

Subtract Y from each side:
-Y = (X >> 2) + (X << 5);

Negate each side:
Y = -(X >> 2) - (X << 5);
Cool, but there's only one problem. It's not an equation! that doesn't mean that when you xor x with (x>>2)+(x<<5)+y you again get x! You ahve to think of the x on the left side of the equation ,and the xs on the right size of the equation as different variables!
Last edited on
Oh duh. yeah I was treating it like it was an equation. I thought that's what he was asking.

Doh!
Try this equation instead:
Z = X ^ ( (X >> 2) + (X << 5) + Y )
I was going to, but then I lost interest. :P
Ahhh. Like the time you were too lazy to make that arcile about "the right way to do binary files" so I did it for you?
Last edited on
Exactly like that. :)
X = X ^ ( (X >> 2) + (X << 5) + Y );
Depending on how information you have to work with, the problem may or may not have a solution.
If all you have is the final value of X, then there's no solution because the operation is destructive. The combination of addition and XOR loses information.
If you have both the initial and final values of X, then it does have a solution:
1
2
//Let x0 be the initial value and x1 the final value.
Y=(x1^x0)-(x0>>2)-(x0<<5);
So, it's solved!
Hellos,
i have the initial X and final but one more problem that this function is in loop, and each time Y is unknown, so, if i want to find out all Y from final to initial X it won't be possible since every loop cycle the X before XOR is unknown..
i knew this, but i had a hope as well that it could be possible =/

anyways, thanks for all your relpies, i found out smth new about xor :)
Woah, what's the problem? If you know the initial x, then you could do it very easily! You just have to store each value in thenfunction to osme variable! If the loop goes to 2, it would be
1
2
Y0=(x1^x0)-(x0>>2)-(x0<<5);
Y1=(x2^x1)-(x1>>2)-(x1<<5);

etc.
Last edited on
the shifts divide and multiply by powers of two
Yes, I know!
Topic archived. No new replies allowed.