我通过UART从热量表接收数据,但我需要一些帮助来了解如何处理数据。 我有文档,但这对我来说还不够,我不太需要这种计算的经验。浮点数据格式符号+指数
也许某个具有合适技能的人可以向我解释如何使用我从文档中获得的更好的示例来完成这项工作。
One value consists of the following bytes:
[number of bytes][sign+exponent] (integer)
(integer) is the register data value. The length of the integer value is
specified by [number of bytes]. [sign+exponent] is an 8-bit value that
specifies the sign of the data value and sign and value of the exponent. The
meaning of the individual bits in the [sign+exponent] byte is shown below:
Examples:
-123.45 = 04h, C2h, 0h, 0h, 30h, 39h
87654321*103 = 04h, 03h , 05h, 39h, 7Fh, B1h
255*103 = 01h, 03h , FFh
现在与实际数据的一个例子。
这是我从这个文件有信息。
这是我从我热量表接收
10 00 56 25 04 42 00 00 1B E4
所以在我的示例然后04是[字节数]一些数据,42是[符号+指数]和00 00 1B E4是(整数)。 但我不知道如何让计算得到实际值。
任何帮助?
我在Arduino草图中使用此代码,并进行了一些修改,以便编译但不应改变结果。 但我有一个问题,当我从我的例子0x42计算SE,然后我得到SE = 1但在Yves Daoust的回复中,然后他得到数字-1。 您对此有何看法? 你能解释一下计算整数的部分吗?当我运行代码的时候,结果是-467992576从字节0x00 0x00 0x1B 0xE4而不是7140(来自另一个回复)。 –
@KristofferIsaksson因为你没有说你需要哪种语言,我无法区分有符号和无符号数字。 'integer'的计算应该作为无符号执行。 –
是的,你是对的,你没有足够的信息来回答我。我声明整数作为unsigned int有更多的东西呢?你对SE的看法如何? –