in reply to Re: increment a hex number
in thread increment a hex number

thanks for the input, but I cannot use 0x030001. I meant to say I need it to be increment from 0x030000 to 0x040000. ideas?

Replies are listed 'Best First'.
Re^3: increment a hex number
by graff (Chancellor) on May 10, 2010 at 22:47 UTC
    Instead of using "+1" (or "++") for the "increment", you would use "+ 0x10000".

    That still involves treating the values as numbers rather than as strings:

    $_ = "0x030000\n"; s/0x([\da-f]+)/sprintf("%#.*x", length($1), hex($1) + 0x10000)/ei; print;
    That snippet will print "0x040000".
      thats dude....that will work!

      The code I do isn't much. I have a hex # converted to binary then using base64 math, I did some division built a key=>value such as 0x010000 => 65536 and thought this way seems silly and what if I miss a hex number. say my array only has 0x010000 to 0x050000....

Re^3: increment a hex number
by toolic (Bishop) on May 10, 2010 at 22:47 UTC
Re^3: increment a hex number
by almut (Canon) on May 10, 2010 at 23:07 UTC

    Like the others said.  BTW, the same arithmetic principle applies to decimal numbers, too:

    30000 + 10000 ------- 40000

    Or any other radix.