473,397 Members | 1,961 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,397 software developers and data experts.

Unpacking Binary Data - not using struct module

I am working on a file conversion project that reads data from a one
file format, reformats in and writes in out to another. The data is
records of informations - names address, account number,statistics.

The numeric values in the original file are stored in what appears to
be a "packed" data format,using a structure that does not use any of
the more standard "C" formats, so I can't use the "struct" module.

As an example, the number "1130" is store using 3 bytes. The HEX
values of the 3 bytes would be 0x01,0x13,0x0F. In other words, the
hex value value "01130f" is unpacked to become "1130".

I believe the original program is written in a version of "Basic" that
dates from the early 90's if that helps.

Currently, I have no problem reading the data. I read the three bytes
and use the binascii.hexilify() function convert the hex values to
their corresponding ASCII values, and then slice off the trailing "f".
In other words;

unpackednumber = int(binascii.hexlify(0x1130f)[:-1])

My questions ...
1) Does anyone recognize this numeric format ?
2) Is there a more efficient module/function I can use, or is the
above the best method?
3) I think that the trailing "f" is sometimes used to indicate the
sign of the number and perhaps even the number of decimal places ...
but am not sure.

Any advice/guidance would be appreciated.
Jul 18 '05 #1
3 4532
Geoffrey wrote:
My questions ...
1) Does anyone recognize this numeric format ?
Seem to be some decimal coded binary, where you only use hexa from 0 to
9, coding corresponding decimal digits.
The trailing hexa F may be used to indicate the end of the number (if
number can have variable length) as it is normally not used as a digit
in this coding.
3) I think that the trailing "f" is sometimes used to indicate the
sign of the number and perhaps even the number of decimal places ...
but am not sure.


Maybe... but have you an example of a negative number ?

A+

Laurent.
Jul 18 '05 #2
Geoffrey wrote:
I am working on a file conversion project that reads data from a one
file format, reformats in and writes in out to another. The data is
records of informations - names address, account number,statistics.

The numeric values in the original file are stored in what appears to
be a "packed" data format,using a structure that does not use any of
the more standard "C" formats, so I can't use the "struct" module.

As an example, the number "1130" is store using 3 bytes. The HEX
values of the 3 bytes would be 0x01,0x13,0x0F. In other words, the
hex value value "01130f" is unpacked to become "1130".

I believe the original program is written in a version of "Basic" that
dates from the early 90's if that helps.

Currently, I have no problem reading the data. I read the three bytes
and use the binascii.hexilify() function convert the hex values to
their corresponding ASCII values, and then slice off the trailing "f".
In other words;

unpackednumber = int(binascii.hexlify(0x1130f)[:-1])

My questions ...
1) Does anyone recognize this numeric format ?
2) Is there a more efficient module/function I can use, or is the
above the best method?
3) I think that the trailing "f" is sometimes used to indicate the
sign of the number and perhaps even the number of decimal places ...
but am not sure.

Any advice/guidance would be appreciated.


It might be some form of floating point. If you can encode numbers like
11300, that might help (also throw in some negative numbers and some
small numbers). I'd like 0 and +/- versions of 2**n for n in range(16)
and +/- versions of 10**n for n in range(1,7).

--Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #3

"Geoffrey" <ge********@hotmail.com> wrote in message
news:6b**************************@posting.google.c om...
1) Does anyone recognize this numeric format ?


Google :)
http://www.room42.com/store/computer..._decimal.shtml
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Pascal | last post by:
Hello, I've a binary file with data in it. This file come from an old ms dos application (multilog ~ 1980). In this application, a field is declared as a 'decimal' (999 999 999.99). I put 0.00...
5
by: Andreas Røsdal | last post by:
Hello, I want to parse a binary file in python. Does python have some built in methods for doing this easily? Any links to example code would be nice.. Thanks Andreas R.
2
by: george young | last post by:
I came across an cool python feature that I've not seen discussed. This may be *implied* by the language reference manual http://docs.python.org/ref/assignment.html], but it was never obvious to...
3
by: Albert Tu | last post by:
Dear there, We have an x-ray CT system. The acquisition computer acquires x-ray projections and outputs multiple data files in binary format (2-byte unsigned integer) such as projection0.raw,...
6
by: David M | last post by:
OK so here is my task. I want to get at the data stored in /var/account/pacct, which stores process accounting data, so that I can make it into a more human understandable format then what the...
3
by: Steve | last post by:
I want to ready binary data from a udp socket effeciently as possible in python. I know of the struct package but do people have any tips when dealing with binary data in python? Is there a...
4
by: Mastastealth | last post by:
I'm trying to create a program to read a certain binary format. I have the format's spec which goes something like: First 6 bytes: String Next 4 bytes: 3 digit number and a blank byte --- Next...
8
by: Bryan.Fodness | last post by:
Hello, I am having trouble writing the code to read a binary string. I would like to extract the values for use in a calculation. Any help would be great. Here is my function that takes in...
3
by: Andrew Lentvorski | last post by:
Basically, I'd like to use the ctypes module as a much more descriptive "struct" module. Is there a way to take a ctypes.Structure-based class and convert it to/from a binary string? Thanks,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.