Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Created December 15, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpluimers/da75280cc974a3f5471c1910dff55902 to your computer and use it in GitHub Desktop.
Save jpluimers/da75280cc974a3f5471c1910dff55902 to your computer and use it in GitHub Desktop.
keeps multiplying by powers of 2 until it finds the widest bitness your system supports
#!/bin/bash
# related to bytesToHuman.bash
# 64-bibt checks at https://superuser.com/questions/1030122/what-is-the-maximum-value-of-a-numeric-bash-shell-variable/1030129#1030129
# perpetual while loop: https://stackoverflow.com/questions/10797835/while-vs-while-true
# expressions: http://tldp.org/LDP/abs/html/arithexp.html
# comparisons: http://tldp.org/LDP/abs/html/comparison-ops.html
b=1
n=1
while :
do
# loop infinitely
printf "%3s %40s\n" "$b" "$n"
b=$(( 1+$b ))
t=$n
n=$(( 2*$n ))
if (( $n < $t )); then
exit
fi
done
echo "the final number on the left is the largest bitness; on the right the largest power of 2 your system supports"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment