I am hacking on the iTunes database format, and I needed to do some quick conversions between hexadecimal and decimal representations. I am decent at it by inspection, but the bigger numbers tend to take me more time than a few keystrokes.
These perl one-liners go both ways. Just add an argument. There is probably already some unix command that will do this, too, but I did not spend time looking for it.
perl -e 'printf "%d\n", hex( shift )'
perl -e 'printf "%X\n", shift'
What you do not see is the -l switch, which I like to use a lot, but does not work with printf(), which I never remember.
Since I want these to stick around, I created some bash aliases. I had to goof around with the quotes, but these work.
alias d2h="perl -e 'printf qq|%X\n|, int( shift )'"
alias h2d="perl -e 'printf qq|%d\n|, hex( shift )'"
Now I need to add a one-liner to do a particular date conversion for iTunes, but I am not thinking about the dates at the moment.
Fileless programs 0 Comments More | Login | Reply /