读取 Windows“二进制文件”浮点到 ASP jscript 变量中
我需要读取由旧版 Windows 应用程序生成的文件,该应用程序以二进制形式存储实数(8 字节“双精度”类型),即作为 8 字节的压缩数组。我可以读取 8 字节组,但如何将其呈现给我的 ASP JScript 代码,以便我可以再次获取真实数字。
或者换句话说:
假设一个文件是由Windows(Delphi)程序生成的:
Assign (f, 'test.bin') ;
rewrite (f, 1) ;
r := 1234.56E78 ;
BlockWrite (f, r, SizeOf (Double)) ;
Close (f) ;
检查该文件将显示它包含8个字节,即:
94 0E 4C CA C2 97 AD 53
这是IEEE格式的实数。假设我可以在 ASP 中读回这 8 个字节,是否有一种简单的方法可以再次获取实数?
I need to read files produced by a legacy Windows app that stores real numbers (the 8-byte "double" type) in binary - i.e. as a packed array of 8 bytes. I can read the 8 byte group OK but how can I present it to my ASP JScript code such I can get the real number back again.
Or to put it another way:
Say a file was produced by a Windows (Delphi) program:
Assign (f, 'test.bin') ;
rewrite (f, 1) ;
r := 1234.56E78 ;
BlockWrite (f, r, SizeOf (Double)) ;
Close (f) ;
Inspection of the file will show it contains 8 bytes, being:
94 0E 4C CA C2 97 AD 53
which is the real number in IEEE format. Assuming I can read these 8 bytes back in ASP, is there a simple way of getting the real number back again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 BitConverter.ToDouble( )。
在 ASP.NET 页面中,这可能如下所示:
它将为您提供输出:(
您可以在 http://babbage.cs.qc.edu/IEEE-754/)
Look at BitConverter.ToDouble().
In an ASP.NET page, this could look like:
Which gets you the output:
(You can check for correctness at http://babbage.cs.qc.edu/IEEE-754/)
感谢奥伦的帮助。巴比奇的东西特别有用。对于这里的价值,我必须编写代码(除了规范之外没有对任何内容进行彻底测试):
Thanks Oren for your help. The babbage stuff was particularly useful. For what it's worth here the code I had to write (not thoroughly tested for anything other than norms):
您可以使用 ADO 流。它用于读取、写入和管理二进制数据或文本流。
不过,您将需要以下功能:
You could use an ADO stream. It is used to read, write, and manage a stream of binary data or text.
You'll need the following function though: