CS Fundamentals intermediate 12 min

Decode a Negative Integer from Fixed-Width Binary

Decode a two's-complement bit pattern before turning a device value into a fake positive number.

Scenario

A device log reports 11110110 from an 8-bit register. One teammate reads it as 246; another insists it is a signed temperature delta and should read as a small negative number. Both are right about the bits and wrong to argue — the same pattern means 246 unsigned and -10 in 8-bit two's complement. The question is which interpretation the firmware intended, and you need both values in front of you to settle it.

Broken input

11110110
width: 8-bit signed

Goal

Use Two's Complement Calculator to decode the bit pattern as a signed two's-complement value while keeping the unsigned reading visible for comparison. Fixed-width matters: the same bits decode differently at 8, 16, or 32 bits.

Tool sequence

  1. Open Two's Complement Calculator.
  2. Set the bit width to 8 first — decoding at the default width silently changes the answer.
  3. Enter the binary pattern 11110110 and read the signed decimal result.
  4. Note the leading 1: in two's complement that is the sign bit, so the value is negative — the calculator shows -10.
  5. If you need the unsigned reading or a hex form for a register map, run the same bits through Binary / Hex / Decimal Converter (246, 0xF6).

Checkpoint output

bits            11110110
unsigned        246
8-bit signed    -10
hex             F6

As an 8-bit two's-complement value the register reads -10 — consistent with a temperature delta, not a count of 246.

Common mistakes

  • Decoding signed data without setting the original bit width — 11110110 at 16 bits is just 246, not -10.
  • Padding or trimming bits before you know the source register size.
  • Calling every value with a leading 1 invalid instead of checking the signed interpretation.
  • Mixing up two's complement with sign-magnitude and getting -118 instead of -10.

Related tools and lessons