- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Convert Hex to Dec
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
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
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
03-06-2003 12:16 PM
03-06-2003 12:16 PM
Convert Hex to Dec
I have a problem with my script, which does convert hex to dec with incorrect values
Part of my scripts reads:
decnum7 = 0
for (i=1;i
tposOP = index(hexstr,substr(OPE,i,1))-1
decnum7=decnum7+((16**(slen7 -i))*tposOP)
} }
printf ("\n0%s %.2d
When using /usr/bin/printf "%d\n" 0xd3fe9906 it returns with error:
printf: Error converting 0xd3fe9906
2147483647 and when visa-visa /usr/bin/printf "%x\n??? 3556677894 it returns d3fe9906??? which is correct. My maxdsiz is set at 2063835136. Is there a better solution besides PERL or C++ that I can use in my script for converting?
Many Thanks
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 12:31 PM
03-06-2003 12:31 PM
Re: Convert Hex to Dec
You could leverage 'bc' and awk's 'system' function. For example:
# awk 'END {system("echo obase=16\;2^39-1|bc")}' < /dev/null
...would output:
7FFFFFFFFF
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 12:35 PM
03-06-2003 12:35 PM
Re: Convert Hex to Dec
Sorry, you wanted the inverse. Therefore, by example (again):
# awk 'END {system("echo ibase=16\;7FFFFFFFFF|bc")}' < /dev/null
...which returns the decimal number:
549755813887
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 12:39 PM
03-06-2003 12:39 PM
Re: Convert Hex to Dec
Warning: 0xNNNN is not understood nor is fe4 (rather than FE4).
As an example do this:
bc
obase=16
ibase=10
FF
quit
Still my preference would be perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 12:59 PM
03-06-2003 12:59 PM
Re: Convert Hex to Dec
Try to print a unsigned integer instead, it works.
# /usr/bin/printf "%u\n" 0xd3fe9906
3556677894
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 01:03 PM
03-06-2003 01:03 PM
Re: Convert Hex to Dec
A.Clay perl is nice, but I am in the learning stages.
JRF I did try bc but not in that fashion (good one). Now how could I apply it wih my script as below:
???.
???..
decnum7 = 0
for (i=1;i
tposOP = index(hexstr,substr(OPE,i,1))-1
decnum7=decnum7+((16**(slen7 -i))*tposOP)
}
printf ("\n0%s %.2d????????????..
Thanks Once again
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 02:16 PM
03-06-2003 02:16 PM
Re: Convert Hex to Dec
OK, if you like the 'bc' approach, I propose define the hex-string you want converted in an awk variable of your choice. Then, again, by way of example, "print" it thusly:
# awk -v VAR=FFF 'END {$0="echo ibase=16\;"VAR"|bc";system($0)}' < /dev/null
Note that the hexadecimal string *must* be *uppercase* characters. Hence, setting VAR=fff would fail -- 'bc' thinks the "fff" is a variable!
You can easily circumvent this, too:
# awk -v VAR=fff 'END {VAR=toupper(VAR);$0="echo ibase=16\;"VAR"|bc";system($0)}' < /dev/null
(...perverse enough, I think...)
Regards!
,,,JRF...