in reply to Re: Mysteries of unpack("a", ...)
in thread Mysteries of unpack("a", ...)
Yah, that looks right. It didn't occur to me to unpack something I've already unpacked. I ended up grabbing substr's of an unpacked bitstring of my original data, in a rather ugly form.
And yes, I also had to correct my math. I'll change it back to (presumably more effecient) bit fiddling tomorrow. For now, here's what I've ended up with:
sub parse_E ($) { my $data = shift; my $databs = unpack ("B32", $data); my $sign = oct ("0b" . substr ($databs, 0, 1)) ? -1 : 1; my $characteristic = oct ("0b" . substr ($databs, 1, 7)) - 64; my $exponent = 16 ** $characteristic; my $fraction = oct ("0b" . substr ($databs, 8, 24)) / 0xfffff +f; my $num = $sign * $fraction * $exponent; return $num; }
Thanks much!
-- Pat
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mysteries of unpack("a", ...)
by gone2015 (Deacon) on Jan 04, 2009 at 01:49 UTC |