To convert the standard 8-bit binary sequence 10110101 to decimal, the exact answer is 181 (assuming an unsigned integer format). The foundational formula used for this conversion is the positional weight sum: \( D = \sum_{i=0}^{n-1} b_i \times 2^i \). Substituting our specific 8-bit values into the formula yields: \( (1 \times 2^7) + (0 \times 2^6) + (1 \times 2^5) + (1 \times 2^4) + (0 \times 2^3) + (1 \times 2^2) + (0 \times 2^1) + (1 \times 2^0) \). Calculating the powers of two gives us \( 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1 \), which sums perfectly to 181.

The Core Formula and Bit-Width Assumptions

When working with microcontrollers like the ESP32-WROOM-32 or Arduino Uno, you are rarely dealing with abstract math; you are reading physical hardware registers. Therefore, the assumption that fixes your final decimal answer is whether the register is read as unsigned (all positive values) or signed (using Two's Complement for negative numbers), alongside the bit-width of the data bus.

Just as AC power calculations shift depending on 120V vs 230V vs 3-phase systems, binary-to-decimal conversions shift drastically depending on 8-bit vs 16-bit vs 32-bit registers:

  • 8-Bit Unsigned (e.g., uint8_t): The sequence 10110101 evaluates to 181. The maximum possible value is 255.
  • 8-Bit Signed (e.g., int8_t): Because the Most Significant Bit (MSB) is 1, the system interprets this as a negative number in Two's Complement. Inverting the bits gives 01001010, adding 1 gives 01001011 (75), making the final decimal answer -75.
  • 16-Bit and 32-Bit Registers: If that same 8-bit byte is zero-extended into a 32-bit ESP32 register (00000000 00000000 00000000 10110101), the decimal value remains 181. However, if it is sign-extended as a 32-bit signed integer (11111111...10110101), the decimal value remains -75. If the byte is part of a larger 16-bit word, endianness (Little-Endian vs Big-Endian) dictates whether this byte represents the high or low multiplier.

Neighboring Values Reference Table (±20% Range)

When debugging SPI or I2C data lines on a logic analyzer, you often need to quickly estimate decimal values without running a full calculation. Below is a spec-sheet-table of binary values within a ±20% range of our target value (145 to 217), allowing for rapid bench-side interpolation.

Decimal Value 8-Bit Binary Hexadecimal Common Use Case / Threshold
145 10010001 0x91 Lower bound of ±20% range
155 10011011 0x9B Common PWM duty cycle (~60%)
165 10100101 0xA5 Mid-range ADC threshold
170 10101010 0xAA Standard UART sync/alternate bit pattern
175 10101111 0xAF High PWM duty cycle (~68%)
181 10110101 0xB5 Target Query Value
190 10111110 0xBE I2C address boundary region
200 11001000 0xC8 High ADC threshold (8-bit)
210 11010010 0xD2 Battery BMS high-cell voltage flag
217 11011001 0xD9 Upper bound of ±20% range

When Binary-to-Decimal Conversion is Meaningless

Applying the standard positional weight formula blindly will yield mathematically correct but functionally useless numbers if the underlying data format is not a pure integer. The conversion becomes meaningless in three common embedded scenarios:

  1. Binary Coded Decimal (BCD): Real-Time Clock (RTC) modules like the DS3231 store time in BCD. The binary sequence 0011 0101 evaluates to 53 using standard integer math. However, in BCD, the high nibble (0011) is 3 and the low nibble (0101) is 5, meaning the actual decimal time value is 35 (e.g., 35 seconds). For deeper reading on data encoding, refer to the Electronics Tutorials binary number guide.
  2. IEEE 754 Floating-Point: If your ESP32 receives a 32-bit payload representing a temperature sensor reading (e.g., 01000000 01001001 00001111 11011100), treating it as a standard integer yields 1,078,525,916. In reality, parsed as an IEEE 754 single-precision float, those exact bits represent the decimal value 3.14159.
  3. ASCII / UTF-8 Text: The byte 01000001 converts to 65 in decimal. But if that byte arrived over a UART serial line from a GPS module, it represents the character 'A', not the number 65.

Frequently Asked Questions

How do I convert a 16-bit binary number to decimal by hand?

Split the 16-bit sequence into two 8-bit bytes. Convert the lower byte (bits 0-7) to decimal normally. Convert the higher byte (bits 8-15) to decimal, and then multiply that high-byte result by 256 (which is \(2^8\)). Add the two results together. For example, 00000001 00000010 is \( (1 \times 256) + 2 = 258 \).

Why does my Arduino serial monitor print negative numbers for large binary values?

This happens when you store a binary value with the MSB set to 1 (e.g., 10110101) into a signed variable type like int8_t or a standard int on an 8-bit AVR board. The compiler interprets the leading 1 as a negative sign via Two's Complement. To fix this and force the positive decimal output (181), cast the variable to uint8_t or unsigned int before printing.

What is the fastest way to convert binary to hex instead of decimal?

Group the binary digits into blocks of four (nibbles) starting from the right. Convert each 4-bit nibble to its single hex character (0-F). For 10110101, split it into 1011 (11 in decimal, which is B in hex) and 0101 (5 in decimal, which is 5 in hex). The result is 0xB5. This avoids complex multiplication and is the preferred method for memory address debugging. See the Texas Instruments application note on binary math for more register-level conversion tricks.

How does endianness change the decimal result of a multi-byte binary array?

Endianness dictates byte order in memory. If you read a 16-bit register containing the bytes 0x12 and 0x34: in Big-Endian (network byte order), the sequence is 0x1234 (decimal 4660). In Little-Endian (used by ARM Cortex-M and ESP32), the bytes are swapped in memory, making the sequence 0x3412 (decimal 13330). Always check your sensor's datasheet for byte-ordering before combining two 8-bit reads into a single 16-bit decimal variable.