in reply to Add 1 to an arbitrary-length binary string
I'm not clear what your data looks like: the question title says "binary string" but the text talks about "text string". Some examples and/or a more complete definition would be helpful.
Incrementing a string representing an unsigned binary number like "001101" is easy: $value =~ s{(^|0)(1*)$}{1 . ("0") x length($2)}e.
Incrementing a string representing an unsigned decimal number like "123456" is an extension of that: $value =~ s{(^|[0-8])(9*)$}{(($1 || 0) + 1) . ("0") x length($2)}e.
There are similar approaches possible for other cases.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Add 1 to an arbitrary-length binary string
by einhverfr (Friar) on Nov 16, 2023 at 02:25 UTC | |
by hv (Prior) on Nov 16, 2023 at 04:29 UTC | |
by karlgoethebier (Abbot) on Nov 16, 2023 at 17:08 UTC | |
by hv (Prior) on Nov 16, 2023 at 19:26 UTC |