in reply to Re^2: Hex to decimal resulting in integer overflow (inc hex regex)
in thread Hex to decimal resulting in integer overflow
Cool, thanks for sharing. I was actually looking for that solution, but just got a tooth extracted today and the brain just wasn't working right.
The 'g' modifier isn't actually necessary there, and adding 'i' lets you remove the upper case entries from the character classes. Of course, the hash lookup is as fast as you're ever going to get, but I'd still probably choose to do the functional solution.
sub incHex { s{ ( [0-9a-f] ) # Any hex digit followed by ( f* )\b # (always) trailing (optional) 'f's }{ sprintf("%x", 1 + hex $1) . '0' x length($2); }iex for @_; }
Very nice though
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hex to decimal resulting in integer overflow (inc hex regex)
by tye (Sage) on Apr 02, 2011 at 02:54 UTC |