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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -