in reply to TO hexadecimal

perl -e 'printf "%x\n", 42'

there's also sprintf and pack. 'perldoc -f sprintf' will get you the docs.