Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Add 1 to an arbitrary-length binary string

by ikegami (Patriarch)
on Nov 16, 2023 at 01:56 UTC ( [id://11155651] : note . print w/replies, xml ) Need Help??


in reply to Re: Add 1 to an arbitrary-length binary string
in thread Add 1 to an arbitrary-length binary string

61FF + 1 = 6200, not 62. (Second test)

  • Comment on Re^2: Add 1 to an arbitrary-length binary string

Replies are listed 'Best First'.
Re^3: Add 1 to an arbitrary-length binary string
by tybalt89 (Monsignor) on Nov 16, 2023 at 02:35 UTC

    That would be true if all strings were hex numbers, but "/Some/Arbitrarily/long/string" (see Re^2: Add 1 to an arbitrary-length binary string) doesn't look like a hex number to me...

    Shouldn't  "61FF" + 1 = "61FG" ?

    If a set of test cases were provided, that could clarify the matter.

      Shouldn't "61FF" + 1 = "61FG" ?

      In short, the string "\x61\xFF" gets incremented to "\x62\x00" ... which seems a reasonable way to do it.
      Perhaps this is already clear (either implicitly or explicitly) from what others have provided to this thread.

      Cheers,
      Rob

      I'm not talking about the string produced by "61FF" but the string produced by "a\xFF", which is a weird and apparently confusing way of referring to the hex number 61FF.

Re^3: Add 1 to an arbitrary-length binary string
by einhverfr (Friar) on Nov 16, 2023 at 02:44 UTC
    actually since this is a range bound, the truncation is fine