Qckng has asked for the wisdom of the Perl Monks concerning the following question:
I'm getting:while (<STDIN>) { chomp; $Pack = pack("H2", $_); print ":$_: packs to :$Pack:\n"; $Un = unpack("H2", $Pack); print ":$Pack: unpacks to :$Un:\n"; }
-1 :-1: packs to :Ñ: :Ñ: unpacks to :d1: -2 :-2: packs to :Ò: :Ò: unpacks to :d2: -3 :-3: packs to :Ó: :Ó: unpacks to :d3:and so on, thru 9. The commercial software is giving me the correct packed character. How can I unpack it to the original negative number (or really, a string of "-1")?
Mini-edit by castaway, swapped runaway bold tag for a br, swapped strange chars for Ñ etc (as my browser killed em in the first edit, oops)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: H2 pack/unpack not working for negative numbers
by nevyn (Monk) on Dec 10, 2003 at 18:04 UTC | |
by Qckng (Initiate) on Dec 10, 2003 at 19:20 UTC | |
by BrowserUk (Patriarch) on Dec 10, 2003 at 20:19 UTC | |
by Anonymous Monk on Dec 10, 2003 at 23:44 UTC | |
by BrowserUk (Patriarch) on Dec 11, 2003 at 00:00 UTC | |
by duff (Parson) on Dec 10, 2003 at 20:15 UTC |