views:

52

answers:

1

Hi All!

I have a formula which calculate position for Y, here it is:

double y = ...;
double minX = ..;
double scaleY = ..;
int MAX_COORD = (1 << 16) - 1;
int sy = ~(int)((y - minY) / scaleY * MAX_COORD) & 0xFFFF;

and now i have sy, and i need to calculate y like this:

y = (sy * scaleY) / MAX_COORD + minY;

but conversion is not equals.. i think it because I don't know how to converse ~ and & operators.

+2  A: 

~x is -x-1, it is it's own inverse.

x & 0xffff is the same as x % 65536. Since several values can map to the same result you cannot invert it, but if the result is in the proper range you can just treat it like the identity, i.e. leave it out.

starblue