- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Converting hex string to integer
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
10-03-2003 01:29 AM
10-03-2003 01:29 AM
E.G. 2bc (string) = 700 (integer)
Thanks, Ed
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:35 AM
10-03-2003 01:35 AM
Re: Converting hex string to integer
adb
0x2bc=D
$q
best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:36 AM
10-03-2003 01:36 AM
Re: Converting hex string to integer
# printf %d\\n 0x2bc
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:42 AM
10-03-2003 01:42 AM
Solution#!/usr/bin/sh
IN="2bc"
OUT=$(echo "obase=10; ibase=16; $(echo ${IN} | tr '[a-f]' '[A-F]')" | bc)
echo "IN = ${IN} OUT = ${OUT}"
Now, If I didn't miss any paren's that should work like a champ. Man bc for details. Note: bc expect hex digits to be uppercase hence the use of 'tr'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:42 AM
10-03-2003 01:42 AM
Re: Converting hex string to integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:43 AM
10-03-2003 01:43 AM
Re: Converting hex string to integer
However, I need to call this over and over again. I tried the following but comes back with a conversion error:
a=2bc
b=`printf %d\n $a`
echo $b
I need to use variable b as a string in other parts of my script.
Thanks, Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:43 AM
10-03-2003 01:43 AM
Re: Converting hex string to integer
---------------------
#! /bin/sh
H=$1
typeset -i10 D=16#$H
echo $D
---------------------
Call the script:
./script 2bc
Regards,
Sergejs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:48 AM
10-03-2003 01:48 AM
Re: Converting hex string to integer
#echo $i
700
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:51 AM
10-03-2003 01:51 AM
Re: Converting hex string to integer
try this:
a=2bc
b=$(printf %d\\n 0x${a})
echo $b
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:52 AM
10-03-2003 01:52 AM
Re: Converting hex string to integer
#/bin/sh
let i=16#$1
echo $i
#chmod u+x x2i.sj
Call it thus:
#x2i.sh 2bc
700
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:53 AM
10-03-2003 01:53 AM
Re: Converting hex string to integer
#/usr/dt/bin/dtcalc
Sorry folks ! for being NON TECHNICAL :-)
think everybody her will excuse me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 01:57 AM
10-03-2003 01:57 AM
Re: Converting hex string to integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 02:29 AM
10-03-2003 02:29 AM
Re: Converting hex string to integer
This sets the input base for bc to hex, the default output is decimal. You can convert to octal and binary (or trinary, quadrary{?},
etc) by changing the argument to ibase. Go the other way by changing the obase or output base: echo "obase=16;700"|bc.
Note that if you set the ibase to a number, and want to change either the ibase or obase afterwards, you'll need to give the argument to that command in the form it is expecting it--not necessarily decimal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2003 02:53 AM
10-03-2003 02:53 AM
Re: Converting hex string to integer
NUM=1
while test "$NUM" -le "256"
do
echo "$NUM \c"
HNUM=`echo "obase=16;$NUM"|bc`
ONUM=`echo "obase=8;$NUM"|bc`
BNUM=`echo "obase=2;$NUM"|bc`
if test "$NUM" -ge "32" -a "$NUM" -le "127"
then
ASCII=`echo "\0$ONUM"`
else
ASCII=""
fi
echo "$HNUM $ONUM $BNUM $ASCII"
(( NUM = "$NUM" + "1" ))
done