<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Working with HEX in scripts in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595240#M33307</link>
    <description>Hi Mike,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You could try something like this&lt;BR /&gt;&lt;BR /&gt;MINOR=$(ls -l /dev/*/group | awk ' {print $6}' | sed "s/0x//;s/0000$//" | sort |tail -1)&lt;BR /&gt;&lt;BR /&gt;MINOR=$(echo "obase=16;$MINOR+1;quit"|bc)&lt;BR /&gt;&lt;BR /&gt;MINOR=0x0${MINOR}0000&lt;BR /&gt;&lt;BR /&gt;echo "The new minor number is $MINOR"&lt;BR /&gt;&lt;BR /&gt;-HTH&lt;BR /&gt;Ramesh</description>
    <pubDate>Tue, 16 Oct 2001 03:19:06 GMT</pubDate>
    <dc:creator>linuxfan</dc:creator>
    <dc:date>2001-10-16T03:19:06Z</dc:date>
    <item>
      <title>Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595236#M33303</link>
      <description>Hey!&lt;BR /&gt;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.)&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help.  I am sure this is a simple question with a simple command, but I don't know what it is :-)&lt;BR /&gt;&lt;BR /&gt;Mike</description>
      <pubDate>Mon, 15 Oct 2001 21:13:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595236#M33303</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-10-15T21:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595237#M33304</link>
      <description>Have a look at 'dc'.  I don't know if this'll do what you want or not, but here's the man page on it.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/hpux/onlinedocs/B2355-90680/B2355-90680.html" target="_blank"&gt;http://docs.hp.com/hpux/onlinedocs/B2355-90680/B2355-90680.html&lt;/A&gt;</description>
      <pubDate>Mon, 15 Oct 2001 21:19:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595237#M33304</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2001-10-15T21:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595238#M33305</link>
      <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;My utility of choice would be bc.&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;bc&lt;BR /&gt;obase=16  # sets output base to hex&lt;BR /&gt;5 + 5     # add 5 decimal + 5 decimal&lt;BR /&gt;A&lt;BR /&gt;quit&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;The other simple answer is to create a small script to simply do decimal to hex conversion:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;while [ $# -ge 1 ]&lt;BR /&gt;  do&lt;BR /&gt;    echo "obase=16;${1};quit" | bc&lt;BR /&gt;    shift&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;you would then execute my.sh 10 20&lt;BR /&gt;to output:&lt;BR /&gt;A&lt;BR /&gt;14&lt;BR /&gt;&lt;BR /&gt;Another variation:&lt;BR /&gt;&lt;BR /&gt;X="0"&lt;BR /&gt;while [ -n "${X}" ]&lt;BR /&gt;  do&lt;BR /&gt;     echo "Enter decimal value (&lt;RETURN&gt; to quit): \c"&lt;BR /&gt;     read X&lt;BR /&gt;     if [ -n "${X}" ]&lt;BR /&gt;       then&lt;BR /&gt;         echo "Hex: \c"&lt;BR /&gt;         echo "obase=16;${X};quit" | bc&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;Man bc for details.&lt;BR /&gt;&lt;BR /&gt;Clay&lt;BR /&gt;&lt;/RETURN&gt;</description>
      <pubDate>Mon, 15 Oct 2001 21:52:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595238#M33305</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-10-15T21:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595239#M33306</link>
      <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;Another way is to do your arithmetic in decimal and let the 'printf' function convert decimal to hexadecimal, as:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;let N=5+5+5&lt;BR /&gt;printf "%#s %#x\n" "N =" $N&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 16 Oct 2001 01:08:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595239#M33306</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-16T01:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595240#M33307</link>
      <description>Hi Mike,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You could try something like this&lt;BR /&gt;&lt;BR /&gt;MINOR=$(ls -l /dev/*/group | awk ' {print $6}' | sed "s/0x//;s/0000$//" | sort |tail -1)&lt;BR /&gt;&lt;BR /&gt;MINOR=$(echo "obase=16;$MINOR+1;quit"|bc)&lt;BR /&gt;&lt;BR /&gt;MINOR=0x0${MINOR}0000&lt;BR /&gt;&lt;BR /&gt;echo "The new minor number is $MINOR"&lt;BR /&gt;&lt;BR /&gt;-HTH&lt;BR /&gt;Ramesh</description>
      <pubDate>Tue, 16 Oct 2001 03:19:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595240#M33307</guid>
      <dc:creator>linuxfan</dc:creator>
      <dc:date>2001-10-16T03:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595241#M33308</link>
      <description>For ksh&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;let dec=16#1F                          &lt;BR /&gt;echo $dec                            &lt;BR /&gt;printf "%d , %x \n" $dec $dec  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Am i a wizard or not?</description>
      <pubDate>Tue, 16 Oct 2001 06:11:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595241#M33308</guid>
      <dc:creator>Carlos Fernandez Riera</dc:creator>
      <dc:date>2001-10-16T06:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595242#M33309</link>
      <description>Hi Mike,&lt;BR /&gt;&lt;BR /&gt;...and using let/typeset:&lt;BR /&gt;&lt;BR /&gt;================================&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;typeset -i16 z&lt;BR /&gt;while [ $# -ne 0 ] ; do&lt;BR /&gt; let z=z+16#$1&lt;BR /&gt; shift&lt;BR /&gt;done&lt;BR /&gt;echo $z | cut -d# -f2&lt;BR /&gt;================================&lt;BR /&gt;&lt;BR /&gt;# ./myscript.ksh e 5 a&lt;BR /&gt;1d&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Tue, 16 Oct 2001 06:20:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595242#M33309</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-10-16T06:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Working with HEX in scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595243#M33310</link>
      <description>Hey Gang!&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Thanks again for all the help!&lt;BR /&gt;Mike</description>
      <pubDate>Wed, 17 Oct 2001 14:26:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/working-with-hex-in-scripts/m-p/2595243#M33310</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-10-17T14:26:28Z</dc:date>
    </item>
  </channel>
</rss>

