Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert hex base16 to integer 5

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
How?

heres my val:
00000e10

How do I make that an int in a shell script?

awk?

 
bc is your friend.

DEC=`echo "ibase=16; E10"|bc`
echo $DEC
3600
 
ps - be sure to enter your hex "digits" in uppercase.
 
I personally use this awk function:
function hex2dec(h ,i,x,v){
h=tolower(h);sub(/^0x/,"",h)
for(i=1;i<=length(h);++i){
x=index("0123456789abcdef",substr(h,i,1))
if(!x)return"NaN"
v=(16*v)+x-1
}
return v
}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
HAHAHA!! Man! Thank you so much...

I have been slaving over this for 4 hours and you give me a 2 line answer that works perfectly... Ahhhhhhhhhh!!!!!

i know nothing.

Thank you thank you thank you!!!
 
Hi,

You can also use printf in your shell

Code:
printf "%d\n" 0x000e10
3600

tested with AIX/ksh and Linux/bash
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top