473,379 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

how to convert 3 byte to float

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
7 7146
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
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
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
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

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

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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

235
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
5
by: Al | last post by:
I am about to start rewriting a fortran program to ansi C++. Would it be best to convert the variables that are 'real' to float? double? long double?
9
by: mprocopio | last post by:
Fellow JavaScripters, I am looking for code or implementation ideas for converting an integer variable to a four-byte array. I'm porting some of my code from C#, where I make use of their...
24
by: djozy | last post by:
Please, how can I convert selected item from dropdown list to integer? Thank you
0
by: Mario M. Mueller | last post by:
Hi, I have a binary file containing 3 byte float values. How can I read them into python? The struct module does not work, since it expects 4 byte floats. Any hints? Mario
4
by: Mason | last post by:
I have tried and tried... I'd like to read in a binary file, convert it's 4 byte values into floats, and then save as a .txt file. This works from the command line (import struct); In : f =...
4
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
1
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, Assuming I have a class/struct with only following types float, int, string what is the most efficient way to pack it to a single byte array before I send it out. I tried to use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.