script for nums in Hexadecimal base


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script for nums in Hexadecimal base
# 1  
Old 10-26-2001
Lightbulb script for nums in Hexadecimal base

Hi:

I´ve developed a script that count in decimal base. this is a example:

ini=0
end=0
ini=$1
end=`expr $2+1`
i=$ini
while [ $end \> $i ]
do
..
..
i=`expr $i+1`
done
Could you say me how dou you count in hexadecimal base?


Thanks
# 2  
Old 10-26-2001
ksh has built-in arithmetic that works in any base. Your script is compatable with ksh. If you just add a first line: "typeset -i16 i", ksh will output the value of i in hexadecimal. The format is ugly. It will be 16#1 16#2 16#3 etc. To get rid of that leading 16#, you can do this:
echo ${i#16#}

And you can switch to ksh arithmetic as well. Instead of:
i=`expr $i + 1`
try this:
((i=i+1))

The built in arithmetic is much faster than using an external process like expr.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate hexadecimal

Hello I'm working on a script to list all ipv6 from given address so I've run this script which create hex part of ipv6 STR2=159 END2=200 SUM2=`expr $END2 - $STR2` for ((i=STR2;i<=END2;++i)); do x=$( printf "%x" $i ) ; echo $x echo -e "::"$x >> netpart.txt done output is : ::9f... (2 Replies)
Discussion started by: nimafire
2 Replies

2. Red Hat

CentOS 6.1 base install (like FreeBSD base install)?

Hello, What is the simplest way to install CentOS 6.1 with console base-system only using official LiveDVD image on VirtualBox machine? I'd like to get simplest console with network support like FreeBSD base installation. Then, install services which I need. The installer jest extracts the... (2 Replies)
Discussion started by: newbie_develope
2 Replies

3. Shell Programming and Scripting

Hexadecimal increment using shell script

I am looking for hexadecimal increment by reading user input using shell script. For example the user input is 01A. I want to increase the hex count by 4 times Looking for output: 01A O1B 01C 01D 01E Can someone suggest? (14 Replies)
Discussion started by: sai_1712
14 Replies

4. Programming

Hexadecimal to ascii

Let's suppose i have a hexadecimal array with 16 cells.for example b3e2d5f636111780 i want to convert it to an array of ascii characters(in C) so that i can reduce total size of the file i want to put it in. But i am afraid i have not fully understand the difference between ascii and hex(i... (3 Replies)
Discussion started by: bashuser2
3 Replies

5. UNIX for Dummies Questions & Answers

Hexadecimal to Decimal

Hi all, I have a small script to convert my HexaDecimal Input to Decimal as output. #!/bin/ksh hd=00208060 dec=`printf %d $hd` echo $dec Output of the above program: printf: 00208060 not completely converted 16 But my expected output is "2130016". How can i acheive this. I... (2 Replies)
Discussion started by: Arunprasad
2 Replies

6. Shell Programming and Scripting

Menu Base AIX Script

Hi, I am trying to create a menu on AIX systen for operators in our office. Please suggest how can I loop back to menu by pressing any key from a online running file. For example I can view the Database alert log file by tail -f command but how should I loop back to menu again. If I press <ctrl... (1 Reply)
Discussion started by: dwiravi
1 Replies

7. AIX

Menu base AIX script

Hi, I am trying to create a menu on AIX systen for operators in our office. Please suggest how can I loop back to menu by pressing any key from a online running file. For example I can view the Database alert log file by tail -f command but how should I loop back to menu again. If I press <ctrl... (1 Reply)
Discussion started by: dwiravi
1 Replies

8. Shell Programming and Scripting

need script to convert number in hexadecimal

hi , i need a script to convert number into hexadecimal base for example: 237=>ED it s very important for me thank you in advance for you help (5 Replies)
Discussion started by: mips
5 Replies

9. Shell Programming and Scripting

Get Hexadecimal Value

I have a record in a file that ends with the new line character "\n". How dio I determine the hexadecimal value for that? (2 Replies)
Discussion started by: lesstjm
2 Replies

10. UNIX for Dummies Questions & Answers

Convert hexadecimal to decimal base

Hello ! Does anyone knows how can I convert hexadecimal to decimal base in the ksh or csh script ?? Thanks ! Witt (1 Reply)
Discussion started by: witt
1 Replies
Login or Register to Ask a Question