Linux / UNIX: bc Convert Octal To Hexadecimal or Vise Versa
You can use the bc command-line calculator tool to convert between octal and hexadecimal number systems in Linux or UNIX systems. Here's how:
Convert Octal to Hexadecimal:
$ echo "ibase=8;obase=16; <octal_number>" | bcWhere <octal_number> is the octal number you want to convert.
Convert Hexadecimal to Octal:
$ echo "ibase=16;obase=8; <hexadecimal_number>" | bcWhere <hexadecimal_number> is the hexadecimal number you want to convert.
Example:
$ echo "ibase=8;obase=16; 177" | bc
7Frn$ echo "ibase=16;obase=8; 7F" | bc
177In these examples, the ibase setting specifies the input base of the number (octal or hexadecimal), and the obase setting specifies the output base (hexadecimal or octal).
