Don't ask to ask, just ask  
PerlMonks 
Re: Convert binary to decimal problemby hawtin (Prior) 
on Apr 07, 2008 at 13:01 UTC ( #678745=note: print w/ replies, xml )  Need Help?? 
The first thing to say is that you are probably converting to a floating point format, rather than a decimal one. The next thing to notice is that your numbers are 24 bits long, this is not the normal way that modern floating point numbers are encoded they tend to be 32 bit (for example see Wikipedia). From memory I think there was an IBM 24 bit float format from the 1970s. As you say the bigendian/littleendian split is worth looking at, also sometime these things are written backwards as well (giving 4 combinations of bit order). The approach I would take is to get as many examples as you can, see if you can encode numbers that are related to each other, for example 1.25, 2.5, 5, 10, 20 and 40. Also select "simple" numbers, like 0.0, 1.0, 1.0 etc and simple relationships, for example compare 0.5, 1.0 and 1.5. Then rewrite every one in binary and see what the patterns are. If you look at the numbers you gave:
There are obviously too few numbers here to see the pattern but I do notice that 500 and 1000 have an obvious relationship. Once I understand the conversion I would then use pack (especially with "b") to unpick the parts (for a float that would be the sign, mantissa and exponent and don't forget any implied MSB).
In Section
Seekers of Perl Wisdom

