By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

how to convert 3 byte to float

P: n/a
Hi,

I have a binary file containing 3 byte float values (big endian). How can I
read them into python? The struct module does not work, since it expects 4
byte floats.

Any hints?

Mario
Dec 8 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Dec 8, 9:34 pm, "Mario M. Mueller" <news.muel...@arcor.dewrote:
Hi,

I have a binary file containing 3 byte float values (big endian). How can I
read them into python? The struct module does not work, since it expects 4
byte floats.

Any hints?

Mario
What does a three-byte float look like? To write an unpack routine
from scratch, one would need to know position & size of the mantissa
and exponent, position of sign bit, how infinities, NaN, -0 etc are
represented (if at all) ...

Dec 8 '07 #2

P: n/a
Mario M. Mueller wrote:
I have a binary file containing 3 byte float values (big endian).
How can I read them into python? The struct module does not work,
since it expects 4 byte floats.
Since the module crystalball is still in development, you'll have to
analyze your three byte float format and convert it either to a
IEEE 754 "single" float and use struct, or convert manually using
bitwise operators.

BTW, who in his mind designs three byte floats? Memory isn't that
expensive anymore. Even C bool is four bytes long.

Regards,
Björn

--
BOFH excuse #87:

Password is too complex to decrypt

Dec 8 '07 #3

P: n/a
Bjoern Schliessmann wrote:

[...]
BTW, who in his mind designs three byte floats? Memory isn't that
expensive anymore. Even C bool is four bytes long.
It's output of a digitizer (but not that old). I was also wondering about
the reason for this limitation (maybe the design is ~20 years old).

Mario
Dec 8 '07 #4

P: n/a
Mario M. Mueller wrote:
It's output of a digitizer (but not that old). I was also
wondering about the reason for this limitation (maybe the design
is ~20 years old).
Uh, that's weird. Since Python cannot guess its format, you'll have
to try it out. Why don't you try to let the device output
well-known values and write a python script to display them
bitwise? With some luck you can reverse engineer the format.

Regards,
Björn

--
BOFH excuse #12:

dry joints on cable plug

Dec 8 '07 #5

P: n/a

On 8 dec 2007, at 13.57, Bjoern Schliessmann wrote:
Mario M. Mueller wrote:
>It's output of a digitizer (but not that old). I was also
wondering about the reason for this limitation (maybe the design
is ~20 years old).

Uh, that's weird. Since Python cannot guess its format, you'll have
to try it out. Why don't you try to let the device output
well-known values and write a python script to display them
bitwise? With some luck you can reverse engineer the format.

Regards,
Björn

--
BOFH excuse #12:

dry joints on cable plug
It will probably require a high quality voltage standard to do this.
There are special high precission
voltage standard chips to do this. For producing other voltages than
the standard voltage of the chip,
use pulsewith modulation with a low pass filter.
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
to************@comhem.se

Dec 8 '07 #6

P: n/a

On 8 dec 2007, at 12.52, Mario M. Mueller wrote:
Bjoern Schliessmann wrote:

[...]
>BTW, who in his mind designs three byte floats? Memory isn't that
expensive anymore. Even C bool is four bytes long.

It's output of a digitizer (but not that old). I was also wondering
about
the reason for this limitation (maybe the design is ~20 years old).

Mario
--
One thing to consider: It is possible that one of the bytes
contributes bits
to BOTH the mantissa and the exponent ; Do you know the relative
accurazy of the digitizer?
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
to************@comhem.se

Dec 8 '07 #7

P: n/a
"Mario M. Mueller" <ne**********@arcor.dewrote:
>Bjoern Schliessmann wrote:

[...]
>BTW, who in his mind designs three byte floats? Memory isn't that
expensive anymore. Even C bool is four bytes long.

It's output of a digitizer (but not that old). I was also wondering about
the reason for this limitation (maybe the design is ~20 years old).
The IEEE-754 standard was adopted in 1985. Before that (and after that,
too), many people used whatever bit layout they wanted for floating point
numbers.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 9 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.