The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bourne and decimals?? kdyzsa Shell Programming and Scripting 1 05-06-2008 10:54 PM
handle decimals subin_bala Shell Programming and Scripting 1 04-21-2008 08:03 AM
Multiplying Floats/Decimals rleebife Shell Programming and Scripting 10 08-02-2007 05:22 AM
comparing two numbers with the decimals chittari Shell Programming and Scripting 4 06-28-2006 10:57 AM
getting the average of a list of decimals. djsal Shell Programming and Scripting 2 04-24-2004 05:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2008
hare hare is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 3
Req on how to convert hex numbers to decimals

Hi,
If i have an input as
c1:41 c2:0x0000.00046b3e
I want to make output display as
c1:41 c2:224062
.
Basically convert first part 0x0000 (as hex) to decimal which is 0 and
convert second part 0x00046b3e (as hex) to decimal which is 289598
and as such add both parts namely 0+289598=289598
.
Is there a way to do this via awk or shell script?
Thanks
Hare.
  #2 (permalink)  
Old 03-21-2008
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
in ksh:
Code:
$ input=0x00046b3e
$ newinput=16#${input##+([0x])}
$ echo $newinput
16#46b3e
$ typeset -i10 output
$ output=$newinput
$ echo $output
289598
$
  #3 (permalink)  
Old 03-21-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
Or with printf:

Code:
printf "%d\n" "0x00046b3"
Regards

Edit: Jim was faster!
  #4 (permalink)  
Old 03-21-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
#!/bin/ksh
# this does the math
echo "c1:41 c2:0x0000.00046b3e" | awk -F[:\.] '{ print $3, $4}' | read one two
result=$( printf "%d + %d" $one  0x"$two")
echo $result
result=$( printf "%d + %d" 0x0x000 0x00046b3e )    # check 
echo $result
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0