2016-02-21 61 views
1

我正在使用Swift接收一些數據的iOS上的藍牙低功耗設備。所述數據在https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.csc_measurement.xml中被指定爲uint16。它使用二進制指數表示,但我找不到如何將其轉換爲浮點數,以便進一步處理它。如何將二進制指數-10的數字轉換爲浮點數?

末尾事件時間信息:單位的分辨率爲1/1024s。

單位:org.bluetooth.unit.time.second

指數:二進制,-10

我心裏算了算10位,小數點前使用第一個段部分第二部分作爲之後的部分。但結果似乎是錯誤的。

任何提示或解決方案,非常感謝。

非常感謝。

回答

2

-10的二進制指數與uint16值轉換爲Double併除以1024.0(或乘以1.0到2到10)相同。

0

要在回答進一步擴大上述由hotpaw2-

一般:

Exponent: Binary, 0 => 001 => 1 decimal Exponent: Binary, -1 => 0.1 => 1/(2^1) => 1/2 => 0.5 decimal Exponent: Binary, -2 => 0.01 => 1/(2^2) => 1/4 => 0.25 decimal Exponent: Binary, -3 => 0.001 => 1/(2^3) => 1/8 => 0.125 decimal

目前在藍牙SIG規範的自行車功率測量特性

定義你的具體情況

末尾事件時間信息:單位的分辨率爲1/1024s。

單位:org.bluetooth.unit.time.second

指數:二進制,-10

. Exponent: Binary,-10 => 0.0000000001 => 1/(2^10) => 1/1024 => 0.0009765625 decimal

現在對於從周邊/服務器來在BLE特性值的數據包分辨率爲1/1024s:. Last_revolution_event_time

Time(seconds) = Last_revolution_event_time * 1/1024

相關問題