- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk decimal -> hex conversion?
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
08-15-2005 06:24 AM
08-15-2005 06:24 AM
On all of our 11.11 systems:
# echo "" | awk {printf("%x\n", 1119965980)}'
42c1531c # Correct:
# echo "" | awk '{printf("%x\n", 2482526102)}'
7fffffff # Incorrect;
On 11.23 systems, it works correctly:
echo "" | awk '{printf("%x\n", 2482526102)}'
93f85796 # Correct:
Even on my linux laptop:
$ echo "" | awk '{printf("%x\n", 2482526102)}'
93f85796
All kernels are 64 bit where appropriate (obviously not on my linux laptop...) I tried installing PHCO_29952 w/no success. Curiously enough, printf works:
# printf "%x\n" 2482526102
93f85796
Anyone know what might be going on? Thanks.
Doug
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:29 AM
08-15-2005 06:29 AM
Re: awk decimal -> hex conversion?
I can confirm that all 6 of my 11.11 systems came up with exactly the same incorrect answer as yours. Odd, indeed.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:46 AM
08-15-2005 06:46 AM
Re: awk decimal -> hex conversion?
7fffffff = 2,147,483,647 (or 2^31 - 1)
which is 1 byte short of 2GB (2^31) if one were talking storage space.
If you do your test with:
echo "" | awk '{printf("%x\n",2147483646)'
you get 7ffffffe which is correct.
I can't explain why it is happening or how to fix it though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:51 AM
08-15-2005 06:51 AM
Re: awk decimal -> hex conversion?
If I remember correctly, the shell can not do
anything more than 247xxxxxxxx somthing.
Which shell are you using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 06:52 AM
08-15-2005 06:52 AM
Re: awk decimal -> hex conversion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 07:08 AM
08-15-2005 07:08 AM
Re: awk decimal -> hex conversion?
with awk.
It does work with printf from within ksh or a posix shell. On an 11.11 machine.
# ksh
# printf "%x\n" 2482526102
93f85796
This kinda looks like a awk bug. where it cant handle a number larger than. 2147483647
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 08:33 AM
08-15-2005 08:33 AM
Re: awk decimal -> hex conversion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 12:26 PM
08-15-2005 12:26 PM
Re: awk decimal -> hex conversion?
Thanks for the replies. I was thinking it had to do with some kind of limit as well; however, it's not the shell's limit as can be proven by observing the printf statement directly.
I was hoping someone would say "Oh yea; apply this patch". That doesn't look like it's going to happen though.
Thanks again for the responses.
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2005 12:46 PM
08-15-2005 12:46 PM
Solutionx=2482526102
echo $x
2482526102
but force the variable to be integer only:
typeset x=2482526102
echo $x
-1812441194
This is because untyped variables start as strings and if used in arithmetic calculations, the equivalent integer value is used. The best way to avoid problems like this is to perform the calculations in bc (and you can convert decimal, octal, hex, etc) and be careful about using shell variables for calculations. If the variable is used as a string and passed to bc, the results will be accurate.
Bill Hassell, sysadmin