Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Wednesday April 30, 2008
02:07 AM

Base conversions

[ #36287 ]

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 )'"

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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 )'"