Function that returns the minimum absolute difference between n and any power of 2
int minDiff ( int n ) { int low = prevPowerof2 ( n ) ; int high = nextPowerOf2 ( n ) ; return min ( n - low , high - n ) ; }