Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-01-2005, 05:33 PM   #1
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, 05:47 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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:

for number in $( seq 1 255 )
  hex_representation=$( printf "%X" ${number} )
  echo "${number}: ${hex_representation}"
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:
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, 06:54 PM   #3
Registered: Jan 2005
Posts: 83

Rep: Reputation: 15
Try this :


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


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 01:25 PM
Successful login from locked screen causes pam_tally to increment. Why? mzmyewski Linux - Security 2 03-03-2005 10:25 AM
PHP set of variables increment? Ctawp Programming 6 06-18-2004 02:03 PM
facing problem in increment operator of set :infinite LOOP ashwinipahuja Programming 0 06-03-2004 01:05 AM
hex? Nox Solaris Linux - Newbie 3 12-07-2002 09:52 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:00 AM.

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