Skip to content

Instantly share code, notes, and snippets.

@kmajetic
Created January 28, 2012 00:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kmajetic/1691795 to your computer and use it in GitHub Desktop.
Save kmajetic/1691795 to your computer and use it in GitHub Desktop.
Convert decimal to binary and the opposite using command line terminal
Decimal to Hexadecimal
10->A
echo 'obase=16;10'| bc
Or
wcalc -h 10
Decimal to Octal
10->12
echo 'obase=8;10' | bc
Or
wcalc -o 10
Decimal to Binary
10->1010
echo 'obase=2;10' | bc
Or
wcalc -b 10
From Hexadecimal to Decimal
echo 'ibase=16;A' | bc (case sensitive)
From Octal to Decimal
echo 'ibase=8;12' | bc
From Binary to Decimal
echo 'ibase=2;1010' | bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment