[PLUG] Stuck with how to unpack a 24 bit FP number in Perl

William A Morita wamorita at hevanet.com
Thu Apr 14 17:20:35 UTC 2005


Pete,

Try unpacking it into 4 bytes with zero in the least significant byte.

You then should be able to have it processed as a normal FP number.

- Bill 
wamorita at hevanet.com 

 

-----Original Message-----
From: plug-bounces at lists.pdxlinux.org
[mailto:plug-bounces at lists.pdxlinux.org] On Behalf Of Pete Lancashire
Sent: Wednesday, April 13, 2005 6:48 PM
To: plug at lists.pdxlinux.org
Subject: [PLUG] Stuck with how to unpack a 24 bit FP number in Perl

I guess just to thick headed, I hope someone can help
 
What I need to do is convert a 24 bit floating point value into a Perl
floating point number.
 
Each numbers 3 bytes/24 bits, where the
least sig. byte is first, and then most sig. byte last, at least the nibble
order is ok :).
                                          
  |7             0|  |15            8|  |23           16|
  |_______|_______|  |_______|_______|  |_______|_______|
  |M|M|M|M|M|M|M|M|  |E|E|M|M|M|M|M|M|  |S|E|E|E|E|E|E|E|
  Least Sig. Byte                       Most Sig. Byte
 
  Sign      1 bit
  Exp       9 bits
  Mantissa 14 bits

  00 60 c0  =  -3.5
  00 00 40  =   2.0
  00 40 40  =   3.0
  00 60 40  =   3.5

Flipping the byte order around is easy, but the unpacking is driving me
nuts. Or can it all be done with unpack ?

-pete "going nuts, this should be simple"


_______________________________________________
PLUG mailing list
PLUG at lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug





More information about the PLUG mailing list