Gross and not portable C99.
#define B6 (1<<5)
#define B17 (1<<16)
unsigned swapbits(unsigned a) {
return ((a & B6 == a & B17) ? a : (a ^ (B6 | B17)));
}
Here's some BFP:
unsigned swapbits(unsigned a) {
unsigned flip = (a & B6 == a & B17);
return (a ^ ((flip<<5) | (flip<<16)));
}
int and
double are C's implicit lingua francas for underspecified literals and implicit type conversions. Throwing
int everywhere is redundant like "ATM machine."