转换 IEEE-754 之前的 C++与 C# 之间的浮点数
在 .Net 之前、在数学协处理器之前、在 IEEE-574 之前,Microsoft 定义了浮点数的位模式。旧版本的 C++ 编译器很乐意使用该定义。
我正在编写一个 C# 应用程序,需要在文件中读取/写入此类浮点数。如何进行 2 位格式之间的转换?我需要两个方向的转换方法。
该应用程序将在 PocketPC/WinCE 环境中运行。
更改文件的结构超出了该项目的范围。
是否有 C++ 编译器选项指示它使用旧的 FP 格式?那将是理想的。然后,我可以使用以 null 结尾的文本字符串在 C# 代码和 C++ 代码之间交换数据,并且 C++ 方法将是 sprintf 和 atof 函数的简单包装器。
至少,我希望有人可以回复旧 FP 格式的位定义,这样我就可以在必要时组合一个低级位操作算法。
谢谢。
Before .Net, before math coprocessors, before IEEE-574, Microsoft defined a bit pattern for floating-point numbers. Old versions of the C++ compiler happily used that definition.
I am writing a C# app that needs to read/write such floating-point numbers in a file. How can I do the conversions between the 2 bit formats? I need conversion methods in both directions.
This app is going to run in a PocketPC/WinCE environment.
Changing the structure of the file is out-of-scope for this project.
Is there a C++ compiler option that instructs it to use the old FP format? That would be ideal. I could then exchange data between the C# code and C++ code by using a null-terminated text string, and the C++ methods would be simple wrappers around sprintf and atof functions.
At the very least, I'm hoping someone can reply with the bit definitions for the old FP format, so I can put together a low-level bit manipulation algorithm if necessary.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我按照 Johannes Rössel 的 Wikipedia 链接 中的面包屑找到了一个不应该的 Python 实现太难翻译:http://groups.google .com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe
以下是该链接中 Bengt Richter 的格式文档:
I followed the bread crumbs from Johannes Rössel's Wikipedia link and found a Python implementation that shouldn't be too hard to translate: http://groups.google.com/group/comp.lang.python/browse_thread/thread/42150ccc20a1d8d5/4aadc71be8aeddbe
Here's the documentation of the format from Bengt Richter in that link:
根据Johannes的回答,您可以访问http://support.microsoft.com/kb/140520 下载 .dll 从 mbf 到 IEEE 转换的源代码。
编辑:实际上,这对你没有帮助。但实际的 MBF 格式记录如下: http://support.microsoft.com/kb/35826:
Based on Johannes's answer, you can go to http://support.microsoft.com/kb/140520 to download the source code for a conversion .dll from mbf to IEEE.
EDIT: Actually, that isn't helpful for you. But the actual MBF format is documented here: http://support.microsoft.com/kb/35826: