将 IEEE 浮点十六进制转换为十进制?
如果我有一个 IEEE 浮点十六进制 42F6E979,如何将其转换为十进制?我相信十进制表示是 = 123.456001
IF I have a IEEE float hex 42F6E979, how do I convert it to decimal? I believe the decimal representation is = 123.456001
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
(大多数)汇编语言实际上并没有非常严格地强制执行类型,因此您只需使用该值初始化一个位置,然后将其视为/使用浮点数。最简单的转换方法通常是这样的:
这实际上会产生二进制编码的十进制,因此您必须将每个字节拆分为两个数字才能显示。当然,这是针对 x86 的——大多数其他架构使这项工作变得更加困难。例如,在 PowerPC 上,您有
fctiw
,它仅转换为整数(与 x86fist
的一般顺序相同)。要使用它,通常需要乘以 10 的倍数以获得所需的小数位数,然后转换为整数,并将小数点放在结果中的正确位置。当/如果 1)您接近浮点数范围的限制,或者 2)您想要比单个整数所能表示的更高的精度时,它可能会变得有点难看。(Most) assembly language doesn't really enforce types very strongly, so you can just initialize a location with that value, and then treat/use it as a float. The easiest way to convert is usually something like:
This actually produces binary coded decimal, so you have to split each byte into two digits for display. Of course, this is for x86 -- most other architectures make the job a tad more difficult. For example, on PowerPC, you have
fctiw
, which just converts to an integer (on the same general order as the x86fist
). To use it, you'd normally multiply by some multiple of 10 to get the number of decimal places you want, then convert to integer, and put a decimal point in the right place in the result. It can get a bit ugly when/if 1) you're close to the limits of the range for a floating point number, or 2) you want more precision than you can represent in a single integer.当您测试自己的代码时,可以使用此在线工具检查你的答案。仅供参考,您是正确的,小数点是 123.45...
维基百科也有一篇有用的文章 。
While you're testing out your own code, you can use this online tool to check your answer. FYI, you are correct in that the decimal is 123.45...
Wikipedia has a useful article as well.
请参阅 Wikipedia 或调用您的环境中可能已存在的库例程。这是一个经常被重新发明的轮子
See Wikipedia or call the library routine that probably already exists in your environment. It's a wheel often re-invented
我将用 C 来做这件事,因为你还没有提供语言。
我将把 toNumber 函数留给 OP 来编写。
I'll do this in C, because you haven't provided a language.
I'll leave it up to the OP to write the toNumber function.