C bitwise integer absolute value
snippet in c

C bitwise integer absolute value

user6991

// Absolute value for integers
int a = -4268;
// mask = a >> 31 -> (mask ^ a) - mask
int abs = ((a >> 31) ^ a) - (a >> 31);