If x> y, then this function will return 1, another wise return is 0.
I still have
int isitGreater(int x, int y) {
return (((y+((~x)+1)) >> 31) & 1);
but it does not work.
Allowed Operating Systems: Legal ops :! ~ and ^ | + <→
I'm sure I have logic, if X is Y and I get a negative number, it means y> x, so the 32nd bit is 1, so I shift this bit to the right 31 times and then "and" with "1" .
edit: this does not work if x is negative, due to overflow. how can i fix this overflow problem without using conditional statements?
source
share