Math Bridge: Signed Sensor Codes

← Back to Signed Sensor Decoding Contracts
Math BridgeElectronicsStruggle-friendly runway

How can the same 12 bits mean −25°C or +231°C?

Separate bit pattern, signed count, physical scale, and sampling limits.

Eddie, the electronics guideEddie guides
The one targetDecode any 12-bit two's-complement temperature code correctly.
The chapter case0xE70, 12 bits, 0.0625°C/LSB, illustrative 1 Hz polling.
What it buys youA testable path from register bits to a bounded physical reading.

A technician must decide whether decoded temperature is safe before changing signed sensor count on the real device. The result is unresolved until the rule and units are checked. Predict the direction first.

See the relationship before changing it

The figure reads from left to right. The blue card is signed sensor count. The middle card applies this page's rule. The green card is decoded 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 signed sensor count, so the numeric fixture does not switch without explanation.

Signed sensor count changes decoded temperature An input card leads through the rule temperature = signed count x 0.0625 degrees C/count to the decoded temperature result. INPUT PAGE INPUT APPLY THE RULE predict calculate check units OUTPUT RESULT
Walk the arrows. Signed decoding makes counts below zero represent temperatures below zero.

Derive the baseline in four named moves

  1. 1

    Name the input. The chapter baseline is -400 counts.

  2. 2

    Name the relationship. temperature = signed count x 0.0625 degrees C/count

  3. 3

    Substitute with units. -400 x 0.0625 = -25.0 degrees C

  4. 4

    Read the result. Keep the unit beside the value. Use it only inside the technical boundary on this page.

Predict, then change signed sensor count

Try Predict the direction of temperature = signed count x 0.0625 degrees C/count. Test another signed sensor count, then compare decoded temperature.

-400 counts
Chapter baseline
Decoded temperature

Observe Signed decoding makes counts below zero represent temperatures below zero. Reset signed sensor count to -400 and compare decoded temperature.

Explain Signed decoding makes counts below zero represent temperatures below zero.

Check yourself

What should you do before trusting a moved-control result?
Answer: Predict its direction, apply the shown relationship, keep the units, and reset to the worked baseline.
What does this small model leave out?
Answer: Only signed sensor count moves here. Field effects named in the technical boundary stay fixed.

1. Start with the physical story

The sensor sends a bit pattern, not a signed JavaScript or C number. Firmware must first isolate the field, then interpret its sign, then apply degrees per count. Correct decoding cannot recover detail already lost to quantisation or slow polling.

Eddie: Preserve the raw bits in evidence; signedness and scale are two separate moves.

2. Name every algebra move

1

Count the codes12 bits give 2¹²=4096 patterns.

2

Find the sign thresholdBit 11 begins at 2¹¹=2048.

3

Sign-extendIf raw≥2048, subtract 4096.

4

Apply physical scaleMultiply the signed count by 0.0625°C.

5

Bound acquisitionUse q/√12 for rounding rms and fs/2 for Nyquist.

3. Reproduce the chapter case

0xE70=3696; 3696≥2048
signed=3696−4096=−400 counts
T=−400(0.0625)=−25.0°C
Tunsigned=3696(0.0625)=+231.0°C
σq=0.0625/√12=0.0180°C; fN=1/2=0.500 Hz

Only the sign-extension move separates the plausible cold result from the +231°C field bug. Sampling and quantisation remain separate limits after decoding succeeds.

4. Try one real input

TryMove the raw 12-bit code across the sign boundary and predict the signed temperature.

Raw code
Signed count
Signed temperature
Wrong unsigned result
Sign bit set
Quantisation rms
Full code span
1 Hz Nyquist
Ideal 12-bit SNR

ObserveAt 0x800, the signed result jumps from the largest positive count to the most negative count. The unsigned path never makes that correction.

ExplainTwo's complement wraps the negative half of the code space; multiplying before sign extension turns valid negative evidence into a large positive error.

Technical boundaries.

This ledger assumes a correctly isolated, right-justified 12-bit field with 0.0625°C per LSB.

Register
Byte order, field alignment, configuration bits, sign convention, and update timing come from the datasheet.
Sensor
Accuracy, offset, noise, response time, self-heating, and calibration exceed quantisation alone.
Sampling
The stated 1 Hz poll is illustrative; the real thermal bandwidth and anti-alias path must be known.

Correct, not complete: this decoder does not validate the register transaction or certify temperature accuracy.

5. Use the result in the design

Keep raw bytes and the extracted field in logs, test both sides of 0x800, apply sign extension before scaling, and compare the result with a reference temperature.

6. Record the evidence state

Record sensor part and mode, register address, byte order, bit width and alignment, raw bytes, extracted hex code, signed count, scale, poll rate, timestamp, and reference reading.

7. Check yourself

Why subtract 4096 from 0xE70?
Answer: Bit 11 is set, so the 12-bit pattern is negative; subtracting 2¹² produces its signed count.
What should 0xFFF decode to?
Answer: 4095−4096=−1 count, then −1×0.0625=−0.0625°C.
Does perfect sign extension prove accurate temperature?
Answer: No. Quantisation, sensor error, polling, filtering, calibration, and register timing remain.
Honesty boundary.

The arithmetic reproduces the chapter's 0xE70, 12-bit, 0.0625°C/LSB case and keeps its 1 Hz sampling assumption explicit.

Register
Byte order, field alignment, configuration bits, sign convention, and update timing come from the datasheet.
Sensor
Accuracy, offset, noise, response time, self-heating, and calibration exceed quantisation alone.
Sampling
The stated 1 Hz poll is illustrative; the real thermal bandwidth and anti-alias path must be known.

Correct, not complete: this decoder does not validate the register transaction or certify temperature accuracy.