I'm shell scripting and I want to round a given integer to the nearest power of two. We can use any standard tools available from the linux command line. You can assume bash. So arithmetic expansion as well as bc would be available.
Rounding to the nearest power of two on a log scale (not as a shell script):
r = 2^(round(log2(x)));
Imagine input to a function and output like this:
# power2 11
8
# power2 12
16
# power2 13
16
# power2 16
16
I'm not sure we have log available to us from a bash shell script. Do we have round? Not sure.
But I know you are super clever and can pull out an elegant and impressive solution.