Bit Twiddling Hacks - Computer Graphics at Stanford University
Compute the sign of an integer int v; // we want to find the sign of v int sign; // the result goes here // CHAR_BIT is the number of bits per byte (normally 8). sign = -(v < 0); // if v < 0 then -1, else 0. // or, to avoid branching on CPUs with flag reg...