take absolute value in c with bitwise operators code example
Example: C bitwise integer absolute value
// Absolute value for integers
int a = -4268;
// mask = a >> 31 -> (mask ^ a) - mask
int abs = ((a >> 31) ^ a) - (a >> 31);
// Absolute value for integers
int a = -4268;
// mask = a >> 31 -> (mask ^ a) - mask
int abs = ((a >> 31) ^ a) - (a >> 31);