in reply to Re^2: signed and unsigned templates in pack/unpack
in thread signed and unsigned templates in pack/unpack
You're packing a negative number with an unsigned template 'N', which means it will be treated as a large positive value. And when you unpack it, it will return that large positive value.
The solution is don't use an unsigned template for packing numbers than can be negative. Use a signed template:
$p = pack 'j', -3544;; print unpack 'j', $p;; -3544
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: signed and unsigned templates in pack/unpack
by posti (Novice) on Mar 02, 2010 at 13:53 UTC |