Ada Audits Signed Sensor Decoding Evidence

Ada re-derives this chapter’s own numbers step by step, at full precision

foundations
math-foundations
calculation-audit
electronics
beginner
Ada ADA · CALCULATION AUDIT

Ada Audits Signed Sensor Decoding Evidence

A 12-bit two’s-complement temperature register reads 0xFFF: taken as an unsigned code it reports a scorching 255.94 °C, yet the same bits decoded with the sign check are a plausible −0.0625 °C, and a matching 0xE70 sample should read −25.0 °C rather than a warm room. Each register is a physics contract of bit width, byte order, signedness, and scale. This audit asks whether a perfectly valid bit pattern can still describe an impossible measurement when firmware skips signedness, shifts the field at the wrong time, or applies the scale before the sign check.

Companion to the chapter Signed Sensor Decoding Contracts — every number here comes from that chapter.

Ada: A signed sensor decoder is a physics contract. The bit width sets the numeric range, and the scale factor turns that range into a plausible temperature or pressure.

1. The sign threshold comes from the bit width. A 12-bit two's-complement field has 2^12 = 4096 codes, so the sign bit is bit 11 and the negative half begins at 2^11 = 2048.

if raw ≥ 2048, signed = raw − 4096; otherwise signed = raw
Audit check Arithmetic shown Physical consequence
Positive TMP102-style sample 0x190 = 400; 400 × 0.0625 °C = 25.0 °C The positive room-temperature case proves byte assembly and scale are plausible.
Negative TMP102-style sample 0xE70 = 3696; 3696 − 4096 = −400; −400 × 0.0625 = −25.0 °C Sign extension happens before scaling, so cold readings stay cold.
Boundary negative code 0xFFF = 4095; 4095 − 4096 = −1; −1 × 0.0625 = −0.0625 °C Reading 0xFFF as unsigned gives 255.94 °C, a decoder bug rather than a sensor fact.
Pressure-register scale (0x01 << 8) | 0x90 = 0x0190 = 400; 400 × 0.25 kPa/LSB = 100 kPa Unsigned fields still need byte order, width, and units recorded beside the code.

2. The audit catches impossible physics early. A valid bit pattern can still describe an impossible measurement if the firmware skips signedness, shifts the field at the wrong time, or applies the scale before the sign check.

Every number above is taken from the chapter’s own material and re-derived step by step.