Decimal to Hex conversion on command line

Dennis Muhlestein djmuhlestein at gmail.com
Mon Sep 9 08:16:30 MDT 2013


On 9/9/13 4:20 AM, Dan Egli wrote:
> Anyone know of a quick and easy way to convert decimal to hexidecimal on
> the command line? Like if I have 0 through 255 and I want $D to contain the
> decimal version, and $H to contain the hex version so that I could do
> something like this:
>
> D=0 while [ $D -lt 256 ] ; do
>
>    <CONVERT $D to Hex $H>
>
> echo Conversion complete, $D converted to $H
>
> D=$(($D + 1));
>
> done

Is it cheating to just use python?

 > H=`python -c "import sys; print hex(int(sys.argv[1]))" 200`; echo $H
0xc8


-Dennis


More information about the PLUG mailing list