- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: hex to decimal
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 01:20 AM
02-20-2002 01:20 AM
I have 4 col's, the 4th col is in hex value (8e00). I would like to awk -printf $1-$4, with the 4th col being converted to dec.
Appreciate the assistance, Chris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 01:26 AM
02-20-2002 01:26 AM
Re: hex to decimal
you could use the typeset- command to convert the format before giving it to awk- script:
typeset -i# var=value
# is for desired system:
typeset -i2 var=8
echo $var
2#100 --> binary system output
echo $var | cut -c3-
100 --> voila, the output you want, system is changable of course
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 01:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 01:56 AM
02-20-2002 01:56 AM
Re: hex to decimal
Thanks, but when in hex (8e00), it should read as 008e, then 0x008e to be converted into dec.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 02:27 AM
02-20-2002 02:27 AM
Re: hex to decimal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2002 04:30 AM
02-20-2002 04:30 AM
Re: hex to decimal
Byte swapped eh?
try this:
echo 1234 2345 3456 8e00 | awk '
{
hexstr="0123456789abcdef"
newnum=tolower(substr($4,3,2) substr($4,1,2))
slen = length(newnum)
decnum = 0
for (i=1; i < slen+1;i++)
{
tpos = index(hexstr,substr(newnum,i,1)) - 1
decnum = decnum + ( (16 ** (slen -i)) * tpos)
}
printf("%s is %d\n",newnum,decnum)
} '
live free or die
harry