Binary and hexadecimal packet inspector
How numbers become bytes: integer and IEEE 754 float layouts, little- versus big-endian byte order, fixed-point scaling with its resolution, range and saturation, and a complete binary IMU packet.
What it demonstrates
How numbers become bytes: integer and IEEE 754 float layouts, little- versus big-endian byte order, fixed-point scaling with its resolution, range and saturation, and a complete binary IMU packet.
How it works
Values are written with a JavaScript DataView, which uses exactly the same byte layouts as Python's struct module and C. In fixed-point mode the transmitted integer is round(value / scale), clipped to the type's range; the receiver multiplies by the scale again. The difference is the quantisation error, at most half a scale step unless the value saturates.
The IMU mode packs a sequence number, a microsecond timestamp and six float32 values in the illustrative layout "<IQ6f" (36 bytes) and decodes it twice: once with the correct byte order and once with the wrong one.
Adjustable parameters
- Wire type (float32, float64, int8/16/32, uint8/16)
- Value
- Fixed-point scale (0.0001–0.1 per LSB)
- Byte order
- IMU gyro, accelerometer and sequence values
Known limitations
- The IMU packet layout is an example, not Asimov's UDP format.
- uint64 timestamps are shown only up to JavaScript's safe-integer range (2^53 µs, about 285 years).
Equations
Core update rule
import struct
raw = round(angle_rad / 0.001) # fixed point, 1 mrad per LSB
payload = struct.pack("<h", raw) # int16, little-endian
angle = struct.unpack("<h", payload)[0] * 0.001
packet = struct.pack("<IQ6f", seq, t_us, gx, gy, gz, ax, ay, az) # 36 bytesExplained in Chapter 5: Communication & Firmware