Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org increment in hex
 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

 11-01-2005, 05:33 PM #1 snutz411 Member   Registered: Mar 2004 Distribution: Slackware 10.0 Posts: 55 Rep: 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
 11-01-2005, 05:47 PM #2 Dark_Helmet Senior Member   Registered: Jan 2003 Posts: 2,786 Rep: 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.
 11-01-2005, 06:54 PM #3 solveit Member   Registered: Jan 2005 Posts: 83 Rep: Try this : Code: ```i=0 while [ \$i -lt 4096 ] do x=`printf "%04X\n" \$i` echo \$x i=`expr \$i + 1` done```

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post andrewb758 Linux - General 5 02-21-2009 01:25 PM mzmyewski Linux - Security 2 03-03-2005 10:25 AM Ctawp Programming 6 06-18-2004 02:03 PM ashwinipahuja Programming 0 06-03-2004 01:05 AM Nox Solaris Linux - Newbie 3 12-07-2002 09:52 AM

LinuxQuestions.org

All times are GMT -5. The time now is 07:11 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -