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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -