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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -