0

I am trying to write an iOS app in Swift that uses the CoreBluetooth framework. I know how to initiate and obtain the values and subscribe to the values I want from the Bluetooth BLE peripheral that I'm using and I'm receiving the values properly. I was looking for help in understanding how to convert the hex code values to a signed floating point number.

Here is the data characteristic information:

enter image description here

Here are a couple data examples:

  1. The gauge displays 0.52705 inches and I receive 0xc0ec063f0100.
  2. The gauge displays -0.41250 and I receive 0x3333d3be0100.
    I understand the last 2 bytes (bytes 5 and 6).

I just can't figure out how to convert the first 4 bytes back to the values shown on the gauge display. Thank you!

ScottK
  • 121
  • 1
  • 4
  • 1
    `"0xc0ec063f0100"`you are getting 6 bytes. And looks like your bytes sequence are big-endian. So you need only the first 4 bytes and use bigendian when converting your bit pattern `Float(bitPattern: UInt32(0xc0ec063f).bigEndian) // 0.52705`. Your fifth byte is 01 which means it is in inches and 00 single mode – Leo Dabus Mar 05 '21 at 21:40
  • 1
    Your second hexa `Float(bitPattern: UInt32(0x3333d3be).bigEndian) // -0.4125` – Leo Dabus Mar 05 '21 at 21:43
  • 1
    Thank you @LeoDabus, that was exactly what I needed. I couldn't find that anywhere. I appreciate it. – ScottK Mar 10 '21 at 13:39

0 Answers0