Using bitwise operator to see if x>y

return (((y+((~x)+1)) >> 31) & 1);but it's not working.Im sure i have the logic right, if X - Y and I get a negative number, that means y > x , so therefore the 32nd bit is a 1, so i shift that bit to the right 31 times and then "and" it with "1".why isnt it working?

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

It depends on the number of bits for int and whether it is signed/unsigned.

int is always signed.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

>> how should I fix my second error?
Use a larger integer type to find the result.

>> and what do you mean by INT_min?
The type int is the default integer type, usually but not necessarily the same size as a WORD on the machine architecture. INT_MIN has to stand for the smallest value that can be represented by this type, and must be at least (-2)^16 IIRC.