Thursday, April 21, 2011

converting hex/decimal/bianry with bash

put this functions in the ~/.bashrc

# convert a number into decimal format
n2d() {
perl -e "printf \"%d\n\", $@"
}

# convert a number into hex format
n2h() {
perl -e "printf \"0x%X\n\", $@"
}

# convert a number into binary format
n2b() {
perl -e "printf \"0b%b\n\", $@"
}