954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Autoincrement of Hex value

Dear All,

Can anybody tell me how to autoincrement the Hexa decimal value.

For Ex:

I am having the value FF0B in Result array and want increment it to FF0C. Now Result array should contain two values.

Diwakar Gana
Newbie Poster
5 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Hello Diwakar Gana!

I'm not 100% sure of the answer, but it looks like there is a related discussion over at perlmonks:

http://www.perlmonks.org/?node_id=839304

I hope this helps!
-G

Gromit
Posting Whiz in Training
212 posts since Sep 2008
Reputation Points: 47
Solved Threads: 31
 

Dear All,

Can anybody tell me how to autoincrement the Hexa decimal value.

For Ex:

I am having the value FF0B in Result array and want increment it to FF0C. Now Result array should contain two values.

(I assume you mean 'increment' because I think 'autoincrement' refers to database table columns.) When you increment a hex string the result is an ordinary decimal number which you have to reformat as a hex string if that's what you want.

#!/usr/bin/perl
use strict;
use warnings;

#Create results array containing one value
my @results = ('FF0B');

#Add 1 to first element and format as hex string for second element
push @results, sprintf('%04X', hex($results[0]) + 1);

#Results array now contains FF0B, FF0C
print 'Results array now contains ', join(', ', @results), "\n";
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

Thanks a lot... Its working now..

Diwakar Gana
Newbie Poster
5 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: