Operating System - HP-UX
1753782 Members
7164 Online
108799 Solutions
New Discussion юеВ

Re: Decimal to Hex conversion

 
Gary Price_2
Occasional Contributor

Decimal to Hex conversion

I have a need to convert Decimal to Hex inside of a korn shell script. Any
suggestions would be appreciated.

Thanks,
Gary
3 REPLIES 3
Wyly O'Brien
New Member

Re: Decimal to Hex conversion

You can use adb(1) to convert decimal to hexadecimal and
hexadecimal to decimal as follows:- To convert decimal 127 to hex type:
echo '0d127=X' | adb
You will receive the following output: 7F
- To convert hex 7F to decimal type:
echo '0x7f=D' | adb
You will receive the following output: 127
Saleem Chaudhary
New Member

Re: Decimal to Hex conversion

This works too. For example to convert 31 to Hex

$printf "%x\n" 31
$1f
Ged Lodder_1
New Member

Re: Decimal to Hex conversion

Try:

#!/usr/bin/ksh

num=$1
typeset -i16 num
print $num # with the base
print ${num#16\#} # without the leading 16#

regards

Ged
PS nice one Saleem