Skip to content

Instantly share code, notes, and snippets.

@dlamblin
Created December 12, 2018 13:40
Show Gist options
  • Save dlamblin/380086f79c5a90b4f5f54d5efcc25828 to your computer and use it in GitHub Desktop.
Save dlamblin/380086f79c5a90b4f5f54d5efcc25828 to your computer and use it in GitHub Desktop.
Print Powers of 2 to 2^64
#!/usr/bin/env perl
use bignum;
$a=1;
for(0..64){
printf "%2s%21s\n", $_, $a;
$a<<=1;
}
# (perl)$ perl -Mbignum -E '$a=1;for(0..64){say" "x($_<10).$_." "x(21-length($a)).$a;$a<<=1}'
# (perl)$ perl -Mbignum -E '$a=1;for(0..64){printf"%2s%21s\n",$_,$a;$a<<=1}'
# (bash)$ p=0 v=1;until [ $p -gt 64 ];do printf '%2s%21s\n' $((p++)) $v;((v<<=1));done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment