0

Convert a decimal number to octal, hexadecimal, binary, or anything

echo 'obase=2;1234' | bc

April 11, 2012bashoneliners

Explanation

  • bc is an arbitrary precision calculator language.
  • obase defines the conversion base for output numbers, in this example 2 (binary)
  • ; is a statement separator in bc
  • 1234 is the decimal number to convert
  • By piping the command to bc we get 1234 in binary format

Alternative one-liners