本文介绍了Float24(24位浮点)到十六进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用浮点24位来存储一个浮点数值在恩智浦编译器MRK III中。它将24位浮点值存储为数据存储器中的3字节十六进制数。 现在,当我使用IEEE 754浮点转换从二进制检索数字回到真实时,我得到了一些非常奇怪的东西。 让我用这样一个例子来说吧 - 注意 - 由于我的编译器支持浮点数24位(和浮点数32一样),所以我赋值的意思就像这样。 示例程序: float24 f24test; float f32test; f32test = 2.9612; f24test =(float24)f32test; 在调试窗口(全局变量)中输出: - f32test = 2.961200e + 000 f24test = 2.9612e + 000 $ b $ $ b $ p $ b $ p $ b $ p $ f32test = 40 3d 84 4d(in hex) f24test = 02 3d 84(十六进制) 问题:现在当我试图在二进制& C中转换 f32test = 40 3d 84 4d(十六进制)然后回到浮动使用IEEE 754,我可以检索2.9612。 同时,当我试图在二进制文件中转换 f24test = 02 3d 84(十六进制)时,然后回到浮动使用IEEE 754,我不能检索2.9612,而不是一些奇怪的价值。 我正在研究这个wiki页面来介绍浮点运算的 - http://en.wikipedia.org/wiki/Single-precision_floating-point_format 我是如果我对1符号位,8位指数& 15位Mantissa。 (浮点数32是1位,8位指数和23位尾数。) 你们中的任何一个人能帮我取得2.9612的值 f24test = 02 3d 84(十六进制) ??? 请问,我一直在努力过去15个小时:( 预先感谢您:) 解决方案 f32test = 40 3d 84 4d(十六进制) f24test = 02 3d 84(十六进制) 在IEEE 754浮点格式中,浮点型指数与偏见。显然,无论您设计的是什么,您所指的24位浮点格式都没有选择使用与IEEE 754 binary32中使用的相同的偏差系统,因为上述两个表示的指数位的值不匹配,指数都用8位表示(根据你)。 在32位表示中,指数用0x80表示,这听起来正确表示一个2到4之间的值。 你可以从24位格式的指数偏移为0x04的假设开始,更多的价值。一个单一的值是不足以让我们理解一个不属于IEEE 754标准的24位浮点格式,显然是设计了一些奇特的选择。I'm using float 24 bit to store a floating point value in a compiler MRK III from NXP. It stores the 24 bit float value as 3 byte Hex in Data memory.Now when I'm using IEEE 754 float point conversion to retrieve the number back from binary to real, I'm getting something very strange.Let me put it this way with an example -Note - "since my compiler supports float 24 bit (along with float 32), I'm assigning value something like this."Sample Program :float24 f24test;float f32test;f32test= 2.9612;f24test= (float24)f32test;Output in debug window (global variable) :- f32test = 2.961200e+000f24test = 2.9612e+000Values stored in the DM(Data Memory at the same time) as captured from debugger - f32test = 40 3d 84 4d (in hex)f24test = 02 3d 84 (in Hex)PROBLEM :-Now when I'm trying to convert f32test = 40 3d 84 4d (in hex) in binary & then back to floating using IEEE 754 , I could retrieve 2.9612.While at the same time when I'm trying to convert f24test = 02 3d 84 (in Hex) in binary & then back to floating using IEEE 754 , I could not retrieve 2.9612 instead some weird value.I'm looking into this wiki page to refer about the floating point arithmetic's -: http://en.wikipedia.org/wiki/Single-precision_floating-point_formatI'm confused why it is not working for the float 24 if I'm using the same format for 1 sign bit, 8 bit exponent & 15 bit Mantissa. (In float 32 it is 1 sign bit, 8 bit exponent & 23 bit Mantissa.)Can any one of you guys help me to get the value 2.9612 back from f24test = 02 3d 84 (in Hex) ???Please do , I've been struggling with this for past 15 hours :(Thank you in advance:) 解决方案 f32test = 40 3d 84 4d (in hex) f24test = 02 3d 84 (in Hex)In IEEE 754 floating-point formats, the floating-point exponent is stored with a bias. Clearly, whoever designed the 24-bit floating-point format you are referring to did not choose to use the same bias system as is used in IEEE 754 binary32, since the values of the exponent bits of the two representations above do not match despite the exponents of both being represented with 8 bits (according to you).In the 32-bit representation, the exponent is represented with the bits 0x80, which sounds about right for the representation of a value between 2 and 4.You could start from the hypothesis that the exponent in the 24-bit format has a bias of 0x04, and confirm this with more values. A single value is not enough for us to make sense of a 24-bit floating-point format that isn't part of the IEEE 754 standard and is obviously designed with some exotic choices. 这篇关于Float24(24位浮点)到十六进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 01:13