- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Working with HEX in scripts
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
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
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-15-2001 02:13 PM
тАО10-15-2001 02:13 PM
I am trying to write a simple script which determines a free node number for use with the mknode command. The real question is, how do I work with hex numbers in shell scripts there must be a simply way (other than writing a conversion in the script.)
Very simply I need to count in hex and not decimal. I need to be able to add 5 + 5 and come up with A (not ten) and add another 5 to it and come up with F, ETC.
Thanks for the help. I am sure this is a simple question with a simple command, but I don't know what it is :-)
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 02:19 PM
тАО10-15-2001 02:19 PM
Re: Working with HEX in scripts
http://docs.hp.com/hpux/onlinedocs/B2355-90680/B2355-90680.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 02:52 PM
тАО10-15-2001 02:52 PM
Re: Working with HEX in scripts
My utility of choice would be bc.
e.g.
bc
obase=16 # sets output base to hex
5 + 5 # add 5 decimal + 5 decimal
A
quit
You will have problems doing a running total because A + 5 in decimal ibase is an error; you could do all input in hex to solve that by specifying ibase=16 as well.
The other simple answer is to create a small script to simply do decimal to hex conversion:
#!/usr/bin/sh
while [ $# -ge 1 ]
do
echo "obase=16;${1};quit" | bc
shift
done
you would then execute my.sh 10 20
to output:
A
14
Another variation:
X="0"
while [ -n "${X}" ]
do
echo "Enter decimal value (
read X
if [ -n "${X}" ]
then
echo "Hex: \c"
echo "obase=16;${X};quit" | bc
fi
done
Man bc for details.
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 06:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 08:19 PM
тАО10-15-2001 08:19 PM
Re: Working with HEX in scripts
You could try something like this
MINOR=$(ls -l /dev/*/group | awk ' {print $6}' | sed "s/0x//;s/0000$//" | sort |tail -1)
MINOR=$(echo "obase=16;$MINOR+1;quit"|bc)
MINOR=0x0${MINOR}0000
echo "The new minor number is $MINOR"
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 11:11 PM
тАО10-15-2001 11:11 PM
Re: Working with HEX in scripts
#! /usr/bin/ksh
let dec=16#1F
echo $dec
printf "%d , %x \n" $dec $dec
Am i a wizard or not?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2001 11:20 PM
тАО10-15-2001 11:20 PM
Re: Working with HEX in scripts
...and using let/typeset:
================================
#!/bin/ksh
typeset -i16 z
while [ $# -ne 0 ] ; do
let z=z+16#$1
shift
done
echo $z | cut -d# -f2
================================
# ./myscript.ksh e 5 a
1d
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-17-2001 07:26 AM
тАО10-17-2001 07:26 AM
Re: Working with HEX in scripts
Thanks for all the help. The final script was too long to place here, but it ended up being a combination of James' printf commands and Ramesh's script.
Thanks again for all the help!
Mike