LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-01-2005, 04:33 PM   #1
snutz411
Member
 
Registered: Mar 2004
Distribution: Slackware 10.0
Posts: 55

Rep: Reputation: 15
increment in hex


is there a way i can write a shell script that will be able to increment in hex?

i.e. i was to get all the values from 000 to FFF
 
Old 11-01-2005, 04:47 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Incrementing by one in hex is the same as incrementing by one in any other number base

My suggestion: Do the increment like normal, and manually convert to hex format when you need to display or compare it to a hex value.

For instance:
Code:
#!/bin/bash

for number in $( seq 1 255 )
do
  hex_representation=$( printf "%X" ${number} )
  echo "${number}: ${hex_representation}"
done
If you're script is given the value of the number to increment in hex notation, you can also use printf to convert it to decimal for you:
Code:
number=$( printf "%d" 0x${hex_representation}" )
I'm not claiming that any of this is efficient by any means. Nor am I saying it will solve all your problems But it should give you a start.
 
Old 11-01-2005, 05:54 PM   #3
solveit
Member
 
Registered: Jan 2005
Posts: 83

Rep: Reputation: 15
Try this :

Code:
i=0

while [ $i  -lt  4096 ]
do
   x=`printf "%04X\n"  $i`
   echo $x
   i=`expr $i + 1`
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash equivalent to C increment operator andrewb758 Linux - General 5 02-21-2009 12:25 PM
Successful login from locked screen causes pam_tally to increment. Why? mzmyewski Linux - Security 2 03-03-2005 09:25 AM
PHP set of variables increment? Ctawp Programming 6 06-18-2004 01:03 PM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 12:05 AM
hex? Nox Solaris Linux - Newbie 3 12-07-2002 08:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration