我通過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的看法如何? –