When debugging embedded systems or analyzing digital logic, you will inevitably capture raw data dumps that require manual translation. While modern tools like the Saleae Logic Pro 8 can automatically decode protocols, understanding the underlying math is critical when a sensor behaves unexpectedly or a register throws a fault code. This walkthrough dissects a classic 8-bit binary number example encountered in I2C temperature sensors, applying rigorous algebraic steps and decision logic to arrive at the correct decimal value.

The Problem Statement: 8-Bit Binary Number Example

Exam Problem:
A microcontroller reads an 8-bit status register from an I2C temperature sensor (e.g., LM75 or TMP102). The raw binary number example captured on the logic analyzer is 1101 0110.

Tasks:
1. Determine the decimal value if the sensor outputs signed data (Two's Complement).
2. Determine the decimal value if the register is strictly unsigned.
3. Justify which interpretation applies to standard temperature sensor fault registers.

Decision Path: Choosing the Correct Conversion Method

Before converting, you must determine the data type. In C/C++ embedded programming, this is dictated by whether the variable is declared as an unsigned integer (uint8_t) or a signed integer (int8_t). Use the following decision tree to select your method:

Condition (MSB Check) Data Type Conversion Method Resulting Range
If MSB (Bit 7) == 0 Unsigned or Signed Standard Positional Notation 0 to +127
If MSB == 1 AND Unsigned uint8_t Standard Positional Notation +128 to +255
If MSB == 1 AND Signed int8_t Radix Complement (Two's Complement) -128 to -1
Concrete Pick / Default Recommendation: For I2C temperature sensors and analog-to-digital converters (ADCs) measuring bipolar signals, the Most Significant Bit (MSB) almost always acts as a sign bit. Default to the Signed Two's Complement method (int8_t) unless the datasheet explicitly defines the register as an unsigned magnitude or raw ADC count.

Step-by-Step Solution: Two's Complement Algebra

The method applied here is the Radix Complement (Base-2) Theorem, commonly known as Two's Complement. This system allows microcontrollers to use the exact same hardware adder circuits for both addition and subtraction, avoiding the need for separate subtraction logic gates. For a deeper theoretical background, refer to the All About Circuits Digital Textbook on Binary Arithmetic.

Part 1: Signed Conversion (Two's Complement)

  1. Identify the Sign: The MSB (Bit 7) of 1101 0110 is 1. This confirms the number is negative.
  2. Invert the Bits (One's Complement): Flip every 1 to 0 and every 0 to 1.
    Original: 1101 0110
    Inverted: 0010 1001
  3. Add 1 (Two's Complement): Add binary 0000 0001 to the inverted result.
    0010 1001 + 0000 0001 = 0010 1010
  4. Convert to Decimal via Positional Polynomial: Map each bit to its base-2 weight (2^0 to 2^7).
    (0 × 2^7) + (0 × 2^6) + (1 × 2^5) + (0 × 2^4) + (1 × 2^3) + (0 × 2^2) + (1 × 2^1) + (0 × 2^0)
    = 0 + 0 + 32 + 0 + 8 + 0 + 2 + 0
    = 42
  5. Apply the Sign: Since the original MSB was 1, apply the negative sign.
    Final Signed Answer: -42

Part 2: Unsigned Conversion (Standard Positional)

If the variable was declared as uint8_t, we ignore the sign implication and simply sum the weights of the original binary number example 1101 0110:

  • Bit 7 (1): 1 × 128 = 128
  • Bit 6 (1): 1 × 64 = 64
  • Bit 5 (0): 0 × 32 = 0
  • Bit 4 (1): 1 × 16 = 16
  • Bit 3 (0): 0 × 8 = 0
  • Bit 2 (1): 1 × 4 = 4
  • Bit 1 (1): 1 × 2 = 2
  • Bit 0 (0): 0 × 1 = 0
  • Sum: 128 + 64 + 16 + 4 + 2 = 214

Sanity Check and Independent Verification

Never submit an exam answer or deploy firmware without a sanity check. Here is how to verify the math independently:

1. Order of Magnitude & Range Check:
An 8-bit signed integer ranges from -128 to +127. Our answer of -42 falls well within this bounds. The unsigned equivalent (214) falls within the 0-255 bounds. The units are dimensionless integers (representing raw ADC counts or temperature in 0.5°C increments, depending on the specific sensor datasheet).

2. The Zero-Sum Verification (Additive Inverse):
In Two's Complement mathematics, adding a number to its negative equivalent must yield zero (ignoring the overflow carry bit). Let's add our original binary to our calculated positive magnitude:
Original (Negative): 1101 0110
Calculated Magnitude: 0010 1010
Addition:
  1101 0110
+ 0010 1010
-----------
1 0000 0000
The 9th bit overflows and is discarded in 8-bit arithmetic, leaving 0000 0000. The math is verified.

Common Exam Traps in Binary Conversions

Trap 1: The 'Minus One' Inversion Error
Students frequently remember to invert the bits but forget to add 1, effectively calculating the One's Complement instead of the Two's Complement. If you forget the +1 step on 1101 0110, you will arrive at -41 instead of the correct -42. Always write out the addition step explicitly on your exam paper to secure partial credit and prevent mental math errors.
Trap 2: The LSB Alignment Shift
When writing out the polynomial expansion (2^0, 2^1, 2^2...), it is common to accidentally align the Least Significant Bit (Bit 0) with 2^1 instead of 2^0. This shifts your entire answer by a factor of two. Always anchor the right-most bit to the 1s column (2^0) before expanding leftward. For more on digital logic fundamentals, consult the University of Maryland CMSC311 Data Representation Notes.

FAQ: Binary Number Example Edge Cases

What happens if the binary number example is exactly 1000 0000?

In an 8-bit signed system, 1000 0000 represents -128. It is a unique edge case because it does not have a positive 8-bit equivalent (+128 overflows the maximum signed value of +127). If you attempt the Two's Complement process on it (invert to 0111 1111, add 1 to get 1000 0000), you get the exact same binary pattern back, which correctly maps to the magnitude of 128, yielding -128.

Does endianness affect this 8-bit binary conversion?

No. Endianness (Big-Endian vs. Little-Endian) only dictates the byte order when dealing with multi-byte variables (16-bit, 32-bit, or 64-bit). For a single 8-bit register, the MSB is always the left-most bit (Bit 7) and the LSB is the right-most bit (Bit 0). However, if your logic analyzer captures a 16-bit temperature reading across two registers, you must verify the sensor's endianness before concatenating the bytes.

How do I handle fractional binary numbers?

If your binary number example includes a radix point (e.g., 1101.0110), the integer portion is solved exactly as shown above. For the fractional portion (right of the radix point), the weights become negative powers of two: 2^-1 (0.5), 2^-2 (0.25), 2^-3 (0.125), etc. You sum the integer and fractional decimal results together to get the final floating-point value.