In: Computer Science
C code required
/*
* 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
*/
#include <stdio.h>
int isGreater(int x, int y) {
int negateAdd = ~x + 1;
int addSum = y + negateAdd;
addSum = addSum >> 31;
return addSum&1;
}
int main(void) {
printf("%d\n", isGreater(4, 5));
printf("%d\n", isGreater(5, 4));
printf("%d\n", isGreater(-5, 6));
printf("%d\n", isGreater(6, -5));
printf("%d\n", isGreater(-4, -5));
printf("%d\n", isGreater(15, 4));
printf("%d\n", isGreater(5, -6));
return 0;
}
===========================================================
SEE OUTPUT
Thanks, PLEASE COMMENT if there is any concern.