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
1indicates 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.
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.
| Decimal | Binary (8-Bit) | Hex | Delta from 181 |
|---|---|---|---|
| 145 | 10010001 | 0x91 | -36 (-20%) |
| 153 | 10011001 | 0x99 | -28 |
| 162 | 10100010 | 0xA2 | -19 |
| 170 | 10101010 | 0xAA | -11 |
| 178 | 10110010 | 0xB2 | -3 |
| 181 | 10110101 | 0xB5 | 0 (Target) |
| 189 | 10111101 | 0xBD | +8 |
| 197 | 11000101 | 0xC5 | +16 |
| 206 | 11001110 | 0xCE | +25 |
| 217 | 11011001 | 0xD9 | +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:
- IEEE 754 Floating-Point: The 32-bit binary
01000000010010010000111111011011converts to1078525915in pure decimal. However, in IEEE 754 single-precision format, it actually represents the float3.14159. You must use memory casting (like a C++unionor Python'sstruct.unpack('!f', bytes)) to decode it. - Binary-Coded Decimal (BCD): Common in Real-Time Clock (RTC) modules like the DS3231. The binary
00100101converts to37in pure decimal. But in BCD, each nibble represents a base-10 digit, meaning the actual value is25(as in 25 minutes past the hour). - 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
5because 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) |
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.






