You can disguise but you can't easily remove if statement since the extraction from an integer is different if the number is positive or negative. This is one of the solutions that basically says: if number is negative do a bit-inversion after subtracting 1 from it, otherwise do nothing.
Code:
int my_abs(int x)
{
int t = (unsigned int)x >> 31; 	
// t is 1 if x is negative 
//otherwise it is 0

return (- t) ^ (x - t); 	
// ^ is XOR and in if t is 1, - 1 will 
//create 32 1's to invert x-1, 
//otherwise x will not change
}
or equally,
Code:
int my_abs(int x)
{
int t = x >> 31; 
// t is -1 if x is negative otherwise it is 0

return t ^ (x + t);
}

Last edited by shabbir; 12Feb2008 at 09:05.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code