How to Convert Octal Number to Hexadecimal Number in Linux
This post will guide you how to convert octal number to hexadecimal number in Linux system. How do I convert from hex to octal using bc command on CentOS/Ubuntu Linux. How to convert number base using echo command in combination with bc command under Linux operating system.
- Convert Octal to Hexadecimal Number
- Convert Hexadecimal Number to Octal Number
- Convert Decimal to Hexadecimal Number
- Convert Decimal to Octal Number
- Convert Decimal to Binary Number
- Convert Hexadecimal to Decimal Number
- Convert Octal to Decimal Number
- Convert Binary to Decimal Number
Convert Octal to Hexadecimal Number
If you want to convert octal to hexadecimal number in bash shell in Linux, you can use the echo command and then combine with bc command to achieve the result. For example, you want to convert a octal number 16 to hex, just type the following command:
$ echo "obase=16; ibase=8; 16" | bc
Outputs:
devops@devops-osetc:~$ echo "obase=16; ibase=8; 16" | bc E
Note: the obase is set to the output base, and the ibase is set to the input base, and 16 is the number that you want to convert.
You can also use the printf command to convert octal to hex number in Linux shell, just type:
$ printf "%X\n" 016
Outputs:
devops@devops-osetc:~$ printf "%X\n" 016 E
Convert Hexadecimal Number to Octal Number
To convert Hexadecimal to Ocatl number, you can execute the following command:
$ echo "obase=8; ibase=16; 16" | bc
or
$ printf "%o\n" 0x16
Outputs:
devops@devops-osetc:~$ echo "obase=8; ibase=16; 16" | bc 26 devops@devops-osetc:~$ printf "%o\n" 0x16 26
Convert Decimal to Hexadecimal Number
To convert Decimal to hex number in bash shell, you can use the following command to achieve the result, type:
$ echo "obase=1;16" | bc
Or
$ printf "%X\n" 16
Outputs:
devops@devops-osetc:~$ echo "obase=16;16" | bc 10 devops@devops-osetc:~$ printf "%X\n" 16 10
Convert Decimal to Octal Number
If you want to convert decimal to octal number, just use one of the following commands:
$ echo "obase=8;16" | bc
Or
$ printf "%o\n" 16
Outputs:
devops@devops-osetc:~$ echo "obase=8;16" | bc 20 devops@devops-osetc:~$ printf "%o\n" 16 20
Convert Decimal to Binary Number
If you want to convert a decimal number to binary in bash shell in Linux, you can execute the following command:
$ echo "obase=2;16" | bc
Outputs:
devops@devops-osetc:~$ echo "obase=2;16" | bc 10000
Convert Hexadecimal to Decimal Number
To convert a hex number to decimal in bash shell, just use the following command:
$ echo "ibase=16;E" | bc
Or
$ printf "%d\n" 0xE
Outputs:
devops@devops-osetc:~$ echo "ibase=16;E" | bc 14 devops@devops-osetc:~$ printf "%d\n" 0xE 14
Convert Octal to Decimal Number
To convert octal to decimal number, type:
$ echo "ibase=8;16" | bc
Or
$ printf "%d\n" o16
Outputs:
devops@devops-osetc:~$ echo "ibase=8;16" | bc 14 devops@devops-osetc:~$ printf "%d\n" 016 14
Convert Binary to Decimal Number
If you want to convert a binary number to decimal in bash shell in Linux, you can use the following command:
$ echo "ibase=2;10000" | bc
Outputs:
devops@devops-osetc:~$ echo "ibase=2;10000" | bc 16