Skip to content

Instantly share code, notes, and snippets.

@pauldotknopf
Created April 12, 2019 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauldotknopf/f73fac8eeb9b3767b135bd2a1d5b5687 to your computer and use it in GitHub Desktop.
Save pauldotknopf/f73fac8eeb9b3767b135bd2a1d5b5687 to your computer and use it in GitHub Desktop.
Helps commands for converting between decimal/binary/hex formats.
function dec-to-hex() {
echo "ibase=10;obase=16;$1" | bc
}
function dec-to-bin() {
echo "ibase=10;obase=2;$1" | bc
}
function hex-to-dec() {
echo "ibase=16;obase=A;$1" | bc
}
function hex-to-bin() {
echo "ibase=16;obase=2;$1" | bc
}
function bin-to-hex() {
echo "ibase=2;obase=10000;$1" | bc
}
function bin-to-dec() {
echo "ibase=2;obase=A;$1" | bc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment