Signed Sensor Decoding Calculation Audit
Signed Sensor Decoding Calculation Audit
Ada re-derives this chapter’s own numbers step by step, at full precision
ADA · CALCULATION AUDIT
Signed Sensor Decoding Calculation Audit
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.
See the relationship before changing it
The figure reads from left to right. The blue card is raw 12-bit code. The middle card applies this page's rule. The green card is signed temperature. Walk the arrows once: set the input, apply the rule, then read the result with its unit.
The retained audit below checks several chapter fixtures. This model keeps those stated values fixed and changes only raw 12-bit code, so the numeric fixture does not switch without explanation.
Derive the baseline in four named moves
- 1
Name the input. The chapter baseline is 3696 code.
- 2
Name the relationship. temperature = (raw code - 4,096) x 0.0625 degrees C
- 3
Substitute with units. (3,696 - 4,096) x 0.0625 = -25.0000 degrees C
- 4
Read the result. Keep the unit beside the value. Use it only inside the technical boundary on this page.
Predict, then change raw 12-bit code
Try Predict the direction of temperature = (raw code - 4,096) x 0.0625 degrees C. Test another raw 12-bit code, then compare signed temperature.
Observe Codes above the sign boundary must be extended before scale is applied or cold becomes falsely hot. Reset raw 12-bit code to 3696 and compare signed temperature.
Explain Codes above the sign boundary must be extended before scale is applied or cold becomes falsely hot.
Check yourself
What should you do before trusting a moved-control result?
What does this small model leave out?
Press Calculate for 12-bit codes 0xFFF and 0xE70 using the 0.0625 C/LSB scale.
Check decodes 0xFFF as -0.0625 C and 0xE70 as -25.0 C instead of the impossible unsigned temperatures.
Codes at or above 2048 represent the negative half, so subtracting 4096 before scaling preserves the two's-complement sign.
Technical boundaries
For the signed decoder, excluded from this fixed arithmetic are bus corruption, register-update races, sensor saturation, calibration drift, or the physical sensor response outside the stated scale.
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.
| 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.