Possible Duplicate:
Find the maximum of two numbers without using if-else or any other comparison operator
isGreater:
if x > y then return 1, else return 0
Example:
- isGreater(4,5) = 0
- isGreater(5,4) = 1
Legal operators: ! ~ & ^ | + << >>
isGreater is the function..
I tried:
int isGreater(int x, int y) {
return (y+(~x+1)) >> 31 & 1;
}
but not working.. :(( Let me know what else I can do?