Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

How to convert Decimal to Octal, binary, Hexadecimal from command line

Date: 2009-02-18 00:00:00 -0400

When you work at routing, you will find yourself converting decimal to binary and the opposite, specially for the masks of the IP address, here I will show you how to do it easily using your command line terminal.

Decimal to Hexadecimal

echo 'obase=16;10'| bc

A

Or

wcalc -h 10

Decimal to Octal

echo 'obase=8;10' | bc

12

Or

wcalc -o 10

Decimal to Binary

echo 'obase=2;10' | bc

1010

Or

wcalc -b 10

From Hexadecimal to decimal

echo 'ibase=16;A' | bc

10

From Octal to Decimal

echo 'ibase=8;12 | bc

10

From Binary to Decimal

echo 'ibase=2;1010 | bc

10

Note: Be sure to have bc or wcalc installed on your system

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.