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