Unix Hex-to-Decimal
Tuesday, May 4th, 2004I had need to convert hex numbers from a data file I was loading into a database into decimal numbers for the database. I figured that there had to be some simple way to do this - after all, we've got decades of Unix here. And sure enough - it came through for me like a champ!
The program is dc and it's easy to get it to convert a hex number to decimal:
echo "16 i FF p q" | dc
returns:
255
I simply put the variable I need into the command:
dec=`echo "16 i ${var} p q" | dc`
and that's it! Nice.