Base conversions

brian_d_foy on 2008-04-30T07:07:47

I think I might have posted these before, but my Perl class at Big Nerd Ranch wanted to see them somewhere they could copy them.

I have shell aliases to convert number bases:

alias d2h="perl -e 'printf qq|%X\n|, int( shift )'"
alias d2o="perl -e 'printf qq|%o\n|, int( shift )'"
alias d2b="perl -e 'printf qq|%b\n|, int( shift )'"
alias h2d="perl -e 'printf qq|%d\n|, hex( shift )'"
alias h2o="perl -e 'printf qq|%o\n|, hex( shift )'"
alias h2b="perl -e 'printf qq|%b\n|, hex( shift )'"
alias o2h="perl -e 'printf qq|%X\n|, oct( shift )'"
alias o2d="perl -e 'printf qq|%d\n|, oct( shift )'"
alias o2b="perl -e 'printf qq|%b\n|, oct( shift )'"


Binary to others

Nibble on 2008-05-06T22:35:41

Thanks, good tip. Here are more aliases:

alias b2h="perl -e 'printf qq|%X\n|, oct( \"0b\" . shift )'"
alias b2d="perl -e 'printf qq|%d\n|, oct( \"0b\" . shift )'"
alias b2o="perl -e 'printf qq|%o\n|, oct( \"0b\" . shift )'"