- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- convert hexa to decimal values
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
04-06-2007 01:01 AM
04-06-2007 01:01 AM
i'm trying to convert an hexadicimal value to decimal but it seems impossible with my knowledge. ;)
that's what i tried (under ksh).
HPUX B.11.00:
# echo 0xfffff000=D |adb
-4096
# printf "%d\n" 0xfffff000
printf: Error converting 0xfffff000
2147483647
# print - $((16#fffff000))
-4096
# echo "obase=86 0xfffff000" |bc -l
syntax error on line 1, /usr/lib/lib.b
# echo "obase=86 ; fffff000" |bc
syntax error on line 1
# echo "fffff000" |tr "[[:xdigit:]]" "[[:digit:]]"
tr: String2 contains an invalid character class.
i've the same errors in HP-UX B.11.11/B.11.23
i need to convert these values for a script so, do you have advice for it ?
Regards,
Cedrick Gaillard
Solved! Go to Solution.
- Tags:
- hex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 01:12 AM
04-06-2007 01:12 AM
Re: convert hexa to decimal values
$ typeset -i10 x=16#fffff000; echo $x
(This returns an unsigned int for 11.23 and 11.31 ksh. sh returns -4096.)
What was wrong with your adb and $(( )) solutions?
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 01:13 AM
04-06-2007 01:13 AM
Re: convert hexa to decimal values
There's nothing wrong with your methodology, only that your numbers exceed 32-bit integers.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 01:48 AM
04-06-2007 01:48 AM
Re: convert hexa to decimal values
i know now that this is because my numbers exceed 32-bit integers.
do you have a solution for convert these values correctly ?
my system is 64bits, is there a 64bit binary who can calculate the result?
the result of 0xfffff000 would be 4294963200, not -4096
and why
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 01:58 AM
04-06-2007 01:58 AM
Re: convert hexa to decimal values
$ echo "4294963200*1234.234"|bc
5300989610188.800
Bill Hassell, sysadmin
- Tags:
- bc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 02:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 02:10 AM
04-06-2007 02:10 AM
Re: convert hexa to decimal values
as indicated behind, i've tried bc, maybe with a wrong syntax:
# echo "obase=86 ; fffff000/1024/1024" |bc
syntax error on line 1,
i've just looking something, at home i've a linux, it have a 32bit processor however, it can convert without problem so, where is the limitation ?
$> uname -s ; printf "%d\n" 0xfffff000
Linux
4294963200
# uname -s ; printf "%d\n" 0xfffff000
HP-UX
printf: Error converting 0xfffff000
2147483647
Regards,
Cedrick Gaillard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 02:27 AM
04-06-2007 02:27 AM
Re: convert hexa to decimal values
Use UPPERCASE hexadecimal digits with 'bc' as I showed above.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 02:29 AM
04-06-2007 02:29 AM
Re: convert hexa to decimal values
the uppercase letter give me no errors from bc now and correct my [io]base variables has gived to me a good result.
problem is solved, thanks ;)
Regards,
Cedrick Gaillard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2007 12:17 PM
04-06-2007 12:17 PM
Re: convert hexa to decimal values
Does it handle arbitrary 64 bit numbers? Like the 11.23 ksh?
I guess it depends on the standard and whether it is worth it to extend it to long longs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 04:00 AM
04-09-2007 04:00 AM
Re: convert hexa to decimal values
#bc
ib=16
FFFFF000
4294963200
^D
#
If you're converting not to many numbers, you could try
#perl -e '$x=0xFFFFF000;print "$x\n"'
429496320
#
If it's a very few numbers, you can go to basics:
FFFFF000 = FFFFFFFF - FFF
FFFFFFFF is one less than x100000000, which is 16^8 (=4294967296), or 4294967295
FFF is one less than x1000 (4095)
4294967295 - 4095 = 4294963200
Or even:
16^8 - 16^3 = 4294963200
(In hex, that's
100000000 - 1000 = 0xFFFFF000)
Here's a short perl routine:
$!/usr/bin/perl
while (
print hex "$_"; print "\n";
}
(For some odd reason, this doesn't work:
print hex "$_\n";
)
and you can always change
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 04:07 AM
04-09-2007 04:07 AM
Re: convert hexa to decimal values
If you wish to use Perl's 'hex' function you can do:
# echo FF|perl -nle 'print hex'
255
(or):
# perl -le 'print hex $ARGV[0]' FFFF
65535
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 09:13 PM
04-09-2007 09:13 PM
Re: convert hexa to decimal values
if you give it as a literal there's even no need for a call of oct() or hex().
$ perl -le 'print 0xfffff000'
4294963200
Obviously, this doesn't work anymore if read from stdin or a file.
$ perl -le 'print shift' 0xfffff000
0xfffff000
then you have to use oct or hex
$ perl -le 'print hex shift' 0xfffff000
4294963200
$ perl -le 'print oct shift' 0xfffff000
4294963200