Shell Script: Convert Hex to Decimal

Objective: Convert a number in hexadecimal representation to decimal format in a shell script

Let’s say that we have a variable h that has a value of 0xFF (hexadecimal).

To convert the representation to decimal, we can use one of the following methods. The first method is by using bc. Note that the ibase tells bc the base of the input number. The output base is by default 10 or decimal.

The next method is to use printf. The 0x prefix is required to indicate that it’s a hexadecimal number.

On bash shell, you can use the the following expressions. A leading 0x denotes hexadecimal. Otherwise, numbers take the form of [base#]n where [base#] is a decimal number representing the arithmetic base, and n is a number in that base.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }