BLE Data Formats: Hexadecimal, Bytes and Endianness
A BLE read can return perfectly valid bytes that still make no sense until you know the value’s format. This lesson turns a hex string into a measurement step by step.
What you’ll learn
- Convert between hexadecimal bytes and decimal values
- Interpret signed values and little- versus big-endian order
- Decode a documented multi-field sensor value without guessing its format
Understand that GATT characteristics hold byte values; the preceding services and UUID lessons explain how to find one.
Bytes are data, not meaning
After a GATT read, an application may receive bytes such as E6 09. Those bytes could be a number, part of a text string, two separate fields, or an application-defined measurement. BLE transports the value; the characteristic specification or device documentation defines how to interpret it. A UUID helps identify the characteristic type, but a custom UUID alone does not explain the bytes.
The format must answer at least: how many bytes belong to each field, whether an integer is signed, which byte comes first, and whether a scale factor or unit applies. Guessing from a single sample may appear to work and fail on the next reading.
Bits, bytes and hexadecimal
A bit is 0 or 1. Eight bits form one byte, whose unsigned value ranges from 0 to 255. Hexadecimal, or hex, uses digits 0–9 and A–F. One hex digit represents four bits, so two hex digits represent one byte. 0x is a common prefix indicating that the following digits are hex.
For example, 0x2A is one byte: 2 sixteens plus 10 ones, which equals decimal 42. The sequence 2A 10 contains two bytes, not the decimal number 2,010. Hex is convenient in logs because byte boundaries and bit patterns remain visible.
Unsigned and signed integers
An unsigned byte treats all eight bits as a nonnegative number: FE is 254. A common signed eight-bit interpretation is two’s complement: the same byte FE represents −2. For a signed one-byte value, values from 00 to 7F are 0 to 127, and 80 to FF represent −128 to −1. The bytes have not changed; the declared format changes their meaning.
For a signed 16-bit value, combine the two bytes in the specified order, then subtract 65,536 if the top bit is set. For example, the unsigned integer 0xFFFE is 65,534; interpreted as signed 16-bit two’s complement, it is −2. Do this conversion only when the field is documented as signed.
Byte order for multi-byte fields
Little-endian puts the least significant byte first. The 16-bit integer 0x1234 appears as 34 12 in little-endian order. Big-endian puts the most significant byte first, so it appears as 12 34. Read the same bytes 34 12 as big-endian and you get 0x3412, a different number.
Bluetooth defines byte order for protocol fields, but an arbitrary characteristic value is interpreted according to its own higher-level definition. Standard GATT characteristic values generally use little-endian unless their defining specification says otherwise; custom application data must document its fields. Do not reverse every BLE byte string indiscriminately: text, single-byte fields, and packed bit fields need different handling.
Decode a fictional temperature field
Define this hypothetical custom format: a two-byte unsigned little-endian integer represents temperature in hundredths of a degree Celsius. It is a teaching example, not the Bluetooth Health Thermometer characteristic format and not a promise about any BleuIO-compatible sensor.
- Receive the bytes
E6 09. - Little-endian order means the integer is
0x09E6. - Convert to decimal:
9 × 256 + 230 = 2,534. - Divide by 100: 25.34 °C.
Decode several fields by offset
Extend that fictional value to four bytes: E6 09 3C 01. The documented layout is: bytes at offsets 0–1 = unsigned little-endian temperature ×100; offset 2 = unsigned humidity percentage; offset 3 = a status byte where bit 0 means the sensor reports valid data. The result is 25.34 °C, 60% humidity (0x3C = 60), and valid status (0x01 has bit 0 set).
| Offset | Bytes | Defined interpretation | Result |
|---|---|---|---|
| 0–1 | E6 09 | Unsigned 16-bit little-endian, divide by 100 | 25.34 °C |
| 2 | 3C | Unsigned 8-bit humidity percentage | 60% |
| 3 | 01 | Status bit 0 = valid | Valid |
Offsets count from zero. If the documentation instead says offset 2 is a checksum or the first byte of another 16-bit field, the interpretation changes. Likewise, 48 69 can represent ASCII “Hi” in a text characteristic, while forcing every binary sensor byte through a text decoder often produces nonsense.
From a BleuIO read to application data
In the recorded HibouAir demonstration, BleuIO reads the Firmware Revision String at discovered value handle 0014 with AT+GATTCREAD=0014. The response includes Value read: 1.1.4, Hex: 0x312E312E34, and Size: 5. Split the hex into bytes 31 2E 31 2E 34; these are ASCII for the five characters 1.1.4.
The characteristic’s defined format tells you that this value is a text string. Other BLE characteristic values may be binary numbers, flags, or structured records. First discover the correct value handle and check its Read property and permissions. The decoder above is deliberately offline so learners can practice byte order without a second device; its fictional temperature format does not apply to this firmware string.
See byte decoding in a real project
In BleuIO’s published HibouAir-to-MQTT project, a HibouAir sensor broadcasts environmental data, BleuIO receives the advertisement, and application code interprets the encoded fields before publishing measurements to an MQTT broker. That project decodes advertising data, not a GATT characteristic read. The same discipline applies to both: identify the documented field layout, parse each offset and type, then attach units before display or forwarding.
The project is a useful next step for developers who want to see byte parsing in a complete data pipeline. Its sensor-specific format should not be applied to unrelated devices.
You’ve completed BLE Architecture and Communication
You now have a layered picture of BLE, know how GAP handles discovery and roles, and can explain how GATT clients use services, characteristics, descriptors, UUIDs and handles. You can also distinguish raw bytes from their documented meaning. Mark this lesson complete below to save progress for Module 2 in this browser.
Next: the Advertising, Scanning and Discovery module examines the packets and observations that begin many BLE interactions. Its published advertising lesson includes the complete BleuIO Web App scanning lab.
Check your understanding
The bytes E6 09 are documented as an unsigned 16-bit little-endian temperature value divided by 100. What is the result?
Key takeaways
- Hex groups bytes; a byte string needs a field definition before it has application meaning.
- Signedness, byte order, offsets and scale factor all affect a decoded value.
- A BleuIO read returns data; interpreting a custom value belongs to the application and device documentation.
Further Reading and Resources
Save your progress in this browser.