in reply to increment a hex number
If you have the numbers 0x000000, 0x010000, 0x020000 and 0x030000, then you can increment them using addition ($array[-1] += 1;) or using the pre- or post-increment operator (++$array[-1]; or $array[-1]++;).
my @nums = ( 0x000000, 0x010000, 0x020000, 0x030000, ); ++$nums[-1]; printf("0x%05X\n", $nums[-1]);
If you have the strings 0x000000, 0x010000, 0x020000 and 0x030000, then you need to convert them to numbers first using hex.
my @formatted_nums = ( '0x000000', '0x010000', '0x020000', '0x030000', ); $formatted_nums[-1] = sprintf("0x%05X\n", hex($formatted_nums[-1]) + 1 +); print("$formatted_nums[-1]\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: increment a hex number
by Anonymous Monk on May 10, 2010 at 22:30 UTC | |
by graff (Chancellor) on May 10, 2010 at 22:47 UTC | |
by Anonymous Monk on May 10, 2010 at 23:00 UTC | |
by toolic (Bishop) on May 10, 2010 at 22:47 UTC | |
by almut (Canon) on May 10, 2010 at 23:07 UTC |