Using ONLY:
! ~ & ^ | + << >>
NO LOOPS
I need to determine the sign of a 32 bit integer and I need to return 1 if positive, 0 if 0 and -1 if ne
Try this:
(x >> 31) | (((0 - x) >> 31) & 1)
How about this:
(x >> 31) | (((~x + 1) >> 31) & 1)
EDIT 2:
In response to issues (or rather nit-picking) raised in the comments...
Assumptions for these solutions to be valid:
0
is the same type as x.