If you are looking at the 8-bit binary sequence 10110101, the direct decimal conversion is 181 (assuming an unsigned integer). The universal formula for base-2 to base-10 conversion is D = Σ(bi × 2i), where b is the bit value (0 or 1) and i is the positional index starting from 0 on the far right. Substituting our specific values: (1 × 27) + (0 × 26) + (1 × 25) + (1 × 24) + (0 × 23) + (1 × 22) + (0 × 21) + (1 × 20), which simplifies to 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1 = 181. However, just as electrical power conversions depend on voltage, phase, and power factor, binary conversions depend entirely on bit-width and sign assumptions. Treating every binary string as a simple unsigned integer will eventually lead to critical debugging errors in embedded systems.
The Base-2 Formula and Neighboring Value Chart
Positional notation in base-2 works exactly like base-10, but each column represents a power of two rather than a power of ten. The rightmost bit is the 1s column (20), the next is the 2s column (21), then 4s, 8s, 16s, and so on. To convert any binary string to decimal, you simply add the column values wherever a 1 appears.
When debugging microcontroller registers or analyzing logic analyzer traces, you rarely need just one isolated number; you need to recognize patterns as values increment. Below is a data-dense reference table showing the ±20% neighborhood around our target value of 181 (ranging from 145 to 217). Notice how the lower-order bits flip rapidly while the higher-order bits remain stable across small increments.
| Decimal | 8-Bit Binary | Hexadecimal | Bit-Flip Delta from 181 |
|---|---|---|---|
| 145 | 10010001 | 0x91 | -36 |
| 153 | 10011001 | 0x99 | -28 |
| 162 | 10100010 | 0xA2 | -19 |
| 171 | 10101011 | 0xAB | -10 |
| 181 | 10110101 | 0xB5 | 0 (Target) |
| 190 | 10111110 | 0xBE | +9 |
| 199 | 11000111 | 0xC7 | +18 |
| 208 | 11010000 | 0xD0 | +27 |
| 217 | 11011001 | 0xD9 | +36 |
What Assumptions Fix the Answer? (Bit-Width and Sign)
In electrical theory, calculating current from power requires knowing if the system is 120V single-phase or 480V three-phase. In digital logic, converting binary to decimal requires knowing the bit-width and the sign representation. The binary string 10110101 does not have a single universal decimal equivalent; its value shifts dramatically based on the architectural assumptions of the processor reading it.
Unsigned vs. Signed (Two's Complement)
If the system treats 10110101 as an 8-bit unsigned integer, the answer is strictly positive: 181. All 8 bits contribute to the magnitude. However, most modern processors (including ARM Cortex-M chips in STM32 boards and AVR chips in Arduinos) use Two's Complement for signed math. In an 8-bit signed system, the Most Significant Bit (MSB) acts as a negative weight of -27 (-128).
Let's recalculate 10110101 using the MSB weight assumption:
(-1 × 128) + (0 × 64) + (1 × 32) + (1 × 16) + (0 × 8) + (1 × 4) + (0 × 2) + (1 × 1)
= -128 + 32 + 16 + 4 + 1 = -75.
Comparison of Interpretations
| System Assumption | Bit-Width | Binary Representation | Decimal Result |
|---|---|---|---|
| Unsigned Integer | 8-bit | 10110101 | 181 |
| Signed Integer (Two's Comp) | 8-bit | 10110101 | -75 |
| Unsigned Integer (Padded) | 16-bit | 0000000010110101 | 181 |
| Signed Integer (Sign-Extended) | 16-bit | 1111111110110101 | -75 |
Notice how padding an 8-bit signed value to 16 bits requires sign extension (copying the MSB into the new upper bits) to preserve the -75 value. If you zero-pad a signed negative number, you accidentally convert it into a massive positive number (65461), a common bug when casting int8_t to uint16_t in C/C++ firmware.
When the Conversion is Meaningless (Context Errors)
Just as calculating the RMS voltage of a DC battery is mathematically possible but practically meaningless, applying the standard base-2 integer formula to non-integer binary formats yields garbage data. Before running the Σ(bi × 2i) formula, verify that the binary string actually represents a standard integer. The conversion becomes meaningless in three common scenarios:
- IEEE 754 Floating-Point Data: If your binary string is 32 bits long and represents a
floatin an ESP32 or Raspberry Pi, the bits are divided into a sign bit, an 8-bit exponent, and a 23-bit mantissa. Applying the standard integer formula to the IEEE 754 standard bit pattern for3.14will yield1078523331. This is mathematically correct for the bit pattern, but entirely useless for understanding the sensor data you are trying to parse. - Binary Coded Decimal (BCD): Real-time clock (RTC) modules like the DS3231 often store time in BCD. In BCD, every 4 bits (nibble) represent a single decimal digit from 0-9. If you read the binary
10110101from an RTC register, the upper nibble is1011(11). Because 11 is outside the 0-9 range, this is an invalid BCD state. Treating it as a pure base-2 integer yields 181, but the actual intended context is a malformed time register. - ASCII / UTF-8 Text Encoding: If the binary sequence is streaming over a UART serial port as text,
10110101isn't a number at all; it is an extended ASCII character (µ). Converting text payloads to integers without first stripping the character encoding layer is a frequent cause of corrupted logging in MQTT and serial debugging.
Quick Conversion Troubleshooting FAQ
Q: Why does my Arduino Serial Monitor print a negative number when I convert a large binary literal?
A: If you assign int x = 0b10110101; on an 8-bit AVR Arduino (like the Uno), the compiler defaults to a signed 16-bit integer, so it prints 181. However, if you explicitly cast it to an int8_t or read it from an 8-bit signed sensor register, the MSB triggers the Two's Complement rule, printing -75. Always check your variable types (uint8_t vs int8_t) before assuming the math is wrong.
Q: How do I handle 64-bit binary conversions manually?
A: Doing the Σ(bi × 2i) math for 64 bits by hand is highly error-prone. Break the 64-bit string into eight 8-bit chunks, convert each chunk to hexadecimal, concatenate the hex string, and use a programmer calculator (like the Windows Calculator in Programmer mode or Python's int('0x...', 16)) to resolve the final 64-bit decimal value. This avoids 263 arithmetic overflow errors in standard calculators.






