To convert the standard 8-bit binary sequence 10110101 to decimal, the exact answer is 181. This assumes an unsigned, big-endian integer format. The foundational formula for positional base-2 to base-10 conversion is D = Σ(b_i × 2^i). Substituting our specific values for 10110101 (reading right-to-left for the exponent i):

Formula Substitution:
(1 × 2⁷) + (0 × 2⁶) + (1 × 2⁵) + (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (0 × 2¹) + (1 × 2⁰)
= 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1 = 181

The Core Assumptions: Bit-Width, Endianness, and Sign

Just as calculating AC power shifts drastically depending on whether you are measuring a 120V single-phase branch circuit, a 230V European mains feed, or a 208V three-phase industrial panel, binary conversion shifts entirely based on register width and sign formatting. The decimal value 181 is fixed only if we assume an 8-bit unsigned integer.

Here is how the answer shifts when the underlying architecture changes:

  • 8-bit Unsigned: 10110101 = 181.
  • 8-bit Signed (Two's Complement): The leading 1 indicates a negative number. The decimal shifts to -75.
  • 16-bit Unsigned (padded): 0000000010110101 = 181.
  • 16-bit Signed: Still 181, because the sign bit (bit 15) is 0.
Bench Tip: When pulling raw ADC data from an ESP32, the SAR ADC outputs a 12-bit unsigned value (0-4095). If you accidentally cast this into an 8-bit variable in your C++ code, the top 4 bits are truncated, and your decimal conversion will silently wrap around, ruining your sensor calibration.

Neighboring Values Reference Table (±20% Range)

When debugging SPI or I2C buses with a logic analyzer, you rarely see the exact target number on the first try. Below is a reference table of binary-to-decimal conversions within a ±20% band of our target value (181), spanning the decimal range of 145 to 217. This helps you quickly spot off-by-one or bit-shift errors in your raw hex/binary dumps.

DecimalBinary (8-Bit)HexDelta from 181
145100100010x91-36 (-20%)
153100110010x99-28
162101000100xA2-19
170101010100xAA-11
178101100100xB2-3
181101101010xB50 (Target)
189101111010xBD+8
197110001010xC5+16
206110011100xCE+25
217110110010xD9+36 (+20%)

When Binary-to-Decimal Conversion is Meaningless

If you dump a 32-bit register from a microcontroller and blindly run it through a base-2 positional formula, you will get a mathematically correct but practically useless number. The standard conversion is meaningless when the binary string represents specialized data formats:

  1. IEEE 754 Floating-Point: The 32-bit binary 01000000010010010000111111011011 converts to 1078525915 in pure decimal. However, in IEEE 754 single-precision format, it actually represents the float 3.14159. You must use memory casting (like a C++ union or Python's struct.unpack('!f', bytes)) to decode it.
  2. Binary-Coded Decimal (BCD): Common in Real-Time Clock (RTC) modules like the DS3231. The binary 00100101 converts to 37 in pure decimal. But in BCD, each nibble represents a base-10 digit, meaning the actual value is 25 (as in 25 minutes past the hour).
  3. Status Bitfields: A fault register where bit 0 is 'Overvoltage', bit 1 is 'Overcurrent', and bit 2 is 'Thermal Shutdown'. Summing these into a single decimal magnitude (e.g., reading 5 because bits 0 and 2 are high) hides the actual diagnostic data. You must use bitwise AND operations (&) to isolate the flags.

Decision Tree: Picking the Right Decoder for Your Microcontroller

Use this decision path to select the exact decoding method for your embedded project. Do not guess the data type; check the sensor datasheet's 'Data Format' section.

IF your sensor outputs...THEN use this format...Concrete Implementation Pick
Raw analog light/distance (e.g., ADC, LDR) Unsigned 12-bit or 16-bit Integer Python: int(raw_bits, 2)
C++: uint16_t(raw)
Temperature/Pressure via I2C (e.g., TMP117, BME280) Signed 16-bit Two's Complement Python: struct.unpack('>h', bytes)
C++: static_cast<int16_t>(raw)
Time/Date via RTC (e.g., DS3231, PCF8523) Binary-Coded Decimal (BCD) C++: ((raw >> 4) * 10) + (raw & 0x0F)
GPS Coordinates or PID constants 32-bit IEEE 754 Float Python: struct.unpack('!f', bytes)
C++: memcpy(&float_var, &raw, 4)
The Default Pick: For 90% of modern I2C/SPI environmental sensors (temperature, humidity, IMUs), the data is transmitted as Signed 16-bit Two's Complement in Big-Endian order. Terminate your decision process here and use struct.unpack('>h', data) in Python or static_cast<int16_t>((msb << 8) | lsb) in C++.

FAQ: Edge Cases in Embedded Binary Math

Q: What happens if I read a 12-bit ADC value into an 8-bit variable?
A: You will experience truncation. The top 4 bits (the most significant bits) are discarded. A 12-bit value of 101011010011 (2771) will be truncated to 11010011 (211). Your decimal conversion will be wildly inaccurate, and your sensor scaling will fail. Always use uint16_t for ADC reads.

Q: How does endianness affect 16-bit conversions?
A: Endianness dictates byte order. If a sensor sends 0x12 then 0x34 (Big-Endian), the 16-bit binary is 0001001000110100 (4660). If your microcontroller reads it as Little-Endian, it swaps the bytes to 0x3412, resulting in 0011010000010010 (13330). Always verify the 'Data Transmission' section of the sensor datasheet to confirm byte order before writing your bit-shift logic.

Q: Why does my negative temperature read as a massive positive number like 65,461?
A: You are reading a Signed 16-bit Two's Complement value as an Unsigned 16-bit integer. The binary for -75 in 16-bit is 1111111110110101. If treated as unsigned, that converts to 65461. Cast the variable to a signed 16-bit integer (int16_t) to force the compiler to recognize the leading '1' as a negative sign bit. For deeper register mapping, consult the ESP32 Technical Reference Manual regarding peripheral data types.