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
I'm not sure this is the absolute ideal way to do things, but I think it's reasonably portable and at least somewhat simpler than what you had:
#define INT_BITS 32 int sign(int v) { return (!!v) | -(int)((unsigned int)v >> (INT_BITS-1)); }