bit manipulation - Bit twiddling to get sign bit of 32 bit int -
i convert
(n < 0 ? 1 : 0)
into bit twiddling (assuming 2s complement arch).
for performance reasons.
with unsigned shift,
x = n >>> 31; // java's unsigned shift x = (int)((uint)n >> 31); // c#'s unsigned shift, casts nop
gcc automatically, other compilers may also. or not. mileage may vary.
Comments
Post a Comment