Direct Answer: If you need to convert the 8-bit binary number 10110101 to decimal, the direct answer is 181 (assuming an unsigned integer). If interpreted as a signed 8-bit integer using two's complement, the answer shifts to -75.
When you are pulling raw bytes off an I2C bus, reading an ESP32 ADC register, or parsing a SPI payload, you rarely have the luxury of a software library doing the math for you. You need to look at a string of ones and zeros and instantly know what it means in base-10. The assumption that fixes your final decimal answer is the data type and bit-width (the digital equivalent of voltage and phase in AC power). A raw binary string is just a pattern; the decimal value depends entirely on the register width (8-bit vs 16-bit vs 32-bit) and whether the most significant bit (MSB) is treated as a sign flag or a standard value.
The Core Conversion Formula and Neighboring Values
To convert a binary number to decimal, you multiply each bit by 2 raised to the power of its position index (starting from 0 on the far right), then sum the results. For our target 8-bit value 10110101, the formula with substituted values looks like this:
(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
When debugging sensor noise or tracking incremental encoder steps, it helps to see the immediate neighboring values to verify if a single flipped bit (like a noisy GPIO line) is causing a massive decimal jump. Here is the ±2 step neighborhood around our target value:
| Binary (8-bit) | Decimal (Unsigned) | Delta from Target |
|---|---|---|
10110011 | 179 | -2 |
10110100 | 180 | -1 |
10110101 | 181 (Target) | 0 |
10110110 | 182 | +1 |
10110111 | 183 | +2 |
How Register Width and Sign Bits Shift the Decimal Answer
Just as a 120V single-phase calculation yields a completely different amperage than a 208V 3-phase calculation, the decimal equivalent of a binary string shifts drastically depending on the microcontroller's register width and sign handling. If you read 10110101 into an 8-bit uint8_t variable in C++, you get 181. If you read it into an 8-bit int8_t (signed), the MSB acts as a negative indicator via two's complement arithmetic, yielding -75.
Furthermore, if that same 8-bit payload is padded into a 16-bit or 32-bit register, the decimal answer shifts again based on whether the system performs sign-extension. Below is a data-dense reference table showing how boundary values shift across unsigned and signed 8-bit contexts, which is critical when configuring ADC thresholds or PWM duty cycles.
| Binary Pattern | Unsigned 8-Bit (uint8_t) | Signed 8-Bit (int8_t) | Common Embedded Context |
|---|---|---|---|
01111111 | 127 | 127 | Max positive value for signed 8-bit I2C sensor data |
10000000 | 128 | -128 | Sign-bit crossover; minimum negative value in two's complement |
10110101 | 181 | -75 | Target value; demonstrates MSB sign inversion |
11111111 | 255 | -1 | All bits high; max unsigned duty cycle, or -1 error code |
00000000 | 0 | 0 | Ground reference / zero-crossing point |
Bench Tip: When reading a 12-bit ADC on an ESP32 (which yields 0-4095), ensure your variable is at least a 16-bit integer (uint16_t). If you accidentally store a 4095 result in an 8-bit variable, it truncates to11111111(255), silently corrupting your voltage calculations.
When Raw Binary-to-Decimal Conversion is Meaningless
There are specific scenarios where applying the standard base-2 positional formula to a binary string will give you a mathematically correct, but practically meaningless, decimal number. You must identify the data encoding before converting.
1. IEEE 754 Floating-Point Data
If your binary string represents a 32-bit float (e.g., 01000000010010010000111111011011), treating it as a raw integer yields 1078523867. This is meaningless. The bits are actually divided into a sign bit, an 8-bit exponent, and a 23-bit mantissa. In reality, that specific binary pattern represents the decimal value 3.14159. Always use a union or a memcpy cast in C/C++ to interpret float registers correctly.
2. Binary Coded Decimal (BCD)
Real-time clock (RTC) modules like the DS3231 often store time in BCD. In BCD, each 4-bit nibble represents a single decimal digit from 0-9. The binary string 0010 0101 converted via standard base-2 math equals 37. But in BCD, the first nibble (0010) is 2, and the second (0101) is 5, meaning the actual value is 25 (e.g., 25 minutes past the hour). Applying standard base-2 conversion to BCD data will result in invalid time calculations.
3. Multi-Byte Endianness Ambiguity
If you receive a 16-bit binary payload over UART as two separate bytes—say, 00000001 (0x01) and 00000010 (0x02)—the decimal answer depends entirely on endianness. In Big-Endian, the combined binary is 0000000100000010 (Decimal 258). In Little-Endian, the bytes are swapped, making the combined binary 0000001000000001 (Decimal 513). Without knowing the transmitting device's byte order, the conversion is a guess.
Frequently Asked Conversion Questions
How do I quickly convert binary to decimal without a calculator?
Memorize the first 8 powers of two: 1, 2, 4, 8, 16, 32, 64, 128. Write them above your binary string from right to left. Simply add up the numbers that sit above a '1'.
Why does my multimeter's logic probe show a different decimal than my code?
Logic probes sample at specific thresholds (usually 0.8V for LOW and 2.0V for HIGH on 5V TTL). If your signal has slow rise times or ringing, the probe might latch a transient '1' that your microcontroller's internal Schmitt trigger filters out, resulting in a mismatched decimal readout.
Can a binary number have a decimal fraction?
Yes, using a binary point (e.g., 101.11). The bits to the right of the point represent negative powers of two (2⁻¹ = 0.5, 2⁻² = 0.25). So 101.11 equals 4 + 1 + 0.5 + 0.25 = 5.75 in decimal. This is common in fixed-point DSP math.






