I would like to know which are the most efficient methods to calculate (-1)^n in terms of bit operations and code length.
The following examples assume integer n:
int a=(n%2==0?1:-1);
int b=(n&1?-1:1);
I don't care about the ease of understanding the code.