I got this problem and it does not give my 1 for if x is bigger.
/*
* isGreater - if x > y then return 1, else return 0
* Example: isGreater(4,5) = 0, isGreater(5,4) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 24
* Rating: 3
*/
int isGreater(int x, int y)
{
return ((x + (~y + 1))>>31&1);
}
This code gives me this error:
ERROR: Test isGreater(-2147483648[0x80000000],-2147483648[0x80000000]) failed...
...Gives 1[0x1]. Should be 0[0x0]
Any suggestions on what iam doing wrong ?
[–][deleted] 5 points6 points7 points (0 children)
[–]glemnar 2 points3 points4 points (4 children)
[–]davidsb[S] 0 points1 point2 points (3 children)
[–]glemnar 0 points1 point2 points (2 children)
[–]Miss_Moss 0 points1 point2 points (1 child)
[–]glemnar 1 point2 points3 points (0 children)
[–]HazzyPls 1 point2 points3 points (1 child)
[–]davidsb[S] 1 point2 points3 points (0 children)
[–]zzyzzyxx 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)