在二进制文件中提取double [英] Extract double in binary file

查看:82
本文介绍了在二进制文件中提取double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个包含数据的二进制文件。

这个文件来自一个旧的ms dos应用程序(multilog~1980 )。

在这个应用程序中,一个字段被声明为''十进制''(999 999

999.99)。

我把0.00在现场并将记录保存到文件。

当我查看二进制文件(使用python或十六进制编辑器)时,

字段存储在8个字节:00-00-00-00-00-00-7F-00。

我尝试从struct模块中解压缩但结果并不好。


有人能帮帮我吗?


谢谢。

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 in the field and save the record to the file.
When I look in the binary file (with python or an hex editor), the
field is stored on 8 bytes: 00-00-00-00-00-00-7F-00.
I try unpack from struct module but the result isn''t good.

Can someone help me?

Thanks.

推荐答案

>

我有一个包含数据的二进制文件。
这个文件来自一个旧的ms dos应用程序(multilog~1980)。
在这个应用程序中,一个字段被声明为''十进制''(999 999
999.99)。
我把0.00放在字段中并将记录保存到文件中。
当我查看二进制文件时le(使用python或十六进制编辑器),
字段存储在8个字节:00-00-00-00-00-00-7F-00。
我尝试从struct module解包但是结果不好。

有人能帮助我吗?

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 in the field and save the record to the file.
When I look in the binary file (with python or an hex editor), the
field is stored on 8 bytes: 00-00-00-00-00-00-7F-00.
I try unpack from struct module but the result isn''t good.

Can someone help me?



最有可能是BCD领域。请在文件中注明数字

一个简单的文字

viewer。在这种情况下,您可以将数字作为字符串读取(长度为

len(''999999999.99'')

或类似)并将其转换为int()或长()。


干杯,


L


Most likely it is a BCD field. Please watch for number in the file with
a simple text
viewer. In that case, you can read the number as a string (length is
len(''999999999.99'')
or similar) and convert it with int() or long().

Cheers,

L




" Gandalf" < GA ***** @ geochemsource.com>在留言中写道

新闻:ma ************************************ * @ pytho n.org ...

"Gandalf" <ga*****@geochemsource.com> wrote in message
news:ma*************************************@pytho n.org...


我有一个包含数据的二进制文件。
这个文件来自一个旧的ms dos应用程序(multilog~1980)。
在这个应用程序中,一个字段被声明为''十进制''(999 999
999.99)。
我把0.00在该字段中并将记录保存到文件。
当我查看二进制文件(使用python或十六进制编辑器)时,
字段存储在8个字节:00-00-00-00 -00-00-7F-00。
我尝试从struct模块中解压缩但结果并不好。

有人可以帮助我吗?


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 in the field and save the record to the file.
When I look in the binary file (with python or an hex editor), the
field is stored on 8 bytes: 00-00-00-00-00-00-7F-00.
I try unpack from struct module but the result isn''t good.

Can someone help me?

<很可能它是一个BCD字段。


Most likely it is a BCD field.




我认为六角形OP给出的是双倍0.0e0(指数有偏见)。

OTOH,11位数的BCD将是6个字节,全部为0,也有。

将-1.0和1.0放在字段中并存储将澄清存储格式

如果真的不知道拥有。


tjr



I believe hex OP gave is for double 0.0e0 (exponents are biased).
OTOH, BCD for 11 digits would be 6 bytes, all 0, which also has.
Putting -1.0 and 1.0 in field and storing would clarify storage format
if really not known.

tjr


pa *********** @ free.fr (Pascal)写道:
pa***********@free.fr (Pascal) writes:
我有一个二进制文件其中的数据。
这个文件来自一个旧的ms dos应用程序(multilog~1980)。
在这个应用程序中,一个字段被声明为''十进制''(999 999
999.99 )。
我把0.00放在字段中并将记录保存到文件中。
当我查看二进制文件(使用python或十六进制编辑器)时,
字段存储在8字节:00-00-00-00-00-00-7F-00。
我尝试从struct模块中解压缩但结果并不好。

有人能帮助我吗?
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 in the field and save the record to the file.
When I look in the binary file (with python or an hex editor), the
field is stored on 8 bytes: 00-00-00-00-00-00-7F-00.
I try unpack from struct module but the result isn''t good.

Can someone help me?




你在这里有点模糊,但我不认为struct会帮助你无论如何都要b $ b。 "十进制"在这种情况下几乎肯定是BCD的某种类型,这不是标准的C结构(因此对于

结构模块是未知的)。


您真的需要弄清楚数据的存储方式。根据您的

一个示例,它看起来像是存储为一系列7位值

表示十进制数字,0x7f表示小数

点。如果这是正确的,你可以使用


tstr =''''

for c in instr:

if c == chr(0x7f):

tstr + =''。''

else:

tstr + = str(ord(c))

fl = float(tstr)


有两个主要警告:

1)这将返回浮动,不是十进制的

2)我甚至无法猜出负数是多少?
代表


- -

克里斯托弗A.克雷格< li ********* @ccraig.org>

权利我们不应该在这里。 " - Sam in Peter Jackson's

The Two Towers站在Osgiliath,他不应该在那里。



You''re sort of vague here, but I don''t think struct is going to help
you regardless. "decimal" in this case is almost certainly some sort
of BCD, which isn''t a standard C struct (and therefore unknown to the
struct module).

You really need to figure out how the data is stored. Based on your
one example it looks like it''s stored as a series of 7 bit values
representing the decimal digits with 0x7f indicating the decimal
point. If this is correct you could use something like

tstr=''''
for c in instr:
if c == chr(0x7f):
tstr+=''.''
else:
tstr += str(ord(c))
fl = float(tstr)

With two major caveats:
1) that this is going to return a float, not a decimal
2) There''s no way for me to even guess how negative numbers are
represented

--
Christopher A. Craig <li*********@ccraig.org>
"By rights we shouldn''t be here." -- Sam in Peter Jackson''s
"The Two Towers" while standing in Osgiliath, where he shouldn''t be.


这篇关于在二进制文件中提取double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆