Bash’s Tools for Base Conversion

  • Bash’s arithmetic expansion allows us to write numbers in any base by prefixing the numeric digits of the base followed by the hash symbol.
$ echo $((2#1001))
9
  • bc allows us to convert effortlessly between bases, using the parameters ibase (for the input base) and obase (for the output base). So, let’s convert the decimal number 9 to base 2
$ echo "ibase=10;obase=2;9" | bc
1001