If you need to know how to convert binary into decimal for the standard 8-bit byte 10110101, the exact decimal answer is 181. This assumes an unsigned, big-endian 8-bit integer. In embedded systems, power monitoring, and digital logic, raw binary from an Analog-to-Digital Converter (ADC) or a shift register must be translated into base-10 to calculate physical metrics like voltage, current, or fault codes. Below is the exact formula, the neighboring value scaling, and the decision path to select the right microcontroller data type for your project.

The Base-2 Formula and Worked Substitution

Binary is a base-2 numeral system where each bit represents a power of 2, starting from $2^0$ on the far right (Least Significant Bit) and increasing to the left. The universal formula for an $n$-bit binary number is:

Formula: $D = (b_{n-1} \times 2^{n-1}) + (b_{n-2} \times 2^{n-2}) + ... + (b_0 \times 2^0)$

Substituting the values for our target byte 10110101:

  • Bit 7 (1): $1 \times 128 = 128$
  • Bit 6 (0): $0 \times 64 = 0$
  • Bit 5 (1): $1 \times 32 = 32$
  • Bit 4 (1): $1 \times 16 = 16$
  • Bit 3 (0): $0 \times 8 = 0$
  • Bit 2 (1): $1 \times 4 = 4$
  • Bit 1 (0): $0 \times 2 = 0$
  • Bit 0 (1): $1 \times 1 = 1$

Sum: $128 + 32 + 16 + 4 + 1 = 181$.

Bench Tip: The assumption that fixes this answer is that the byte is unsigned. If your microcontroller interprets 10110101 as an 8-bit signed integer (Two's Complement), the leading '1' indicates a negative number, and the decimal value shifts to -75. Always verify your compiler's data type before passing raw I2C/SPI register data into math functions.

Neighboring Values and ADC Voltage Scaling

When reading sensors, you rarely get just one isolated number; you get a stream of data. Here is a reference table covering a ±20% range around our target decimal (145 to 217), mapped to the physical voltages they represent when read by common 8-bit and 10-bit ADC architectures.

Binary (8-Bit) Decimal Voltage @ 5.0V Ref (8-bit) Voltage @ 3.3V Ref (10-bit mapped)
10010001 145 2.84 V 1.43 V
10100000 160 3.13 V 1.58 V
10110101 181 3.54 V 1.79 V
11001000 200 3.92 V 1.98 V
11011001 217 4.25 V 2.14 V

Note: 10-bit mapped values assume the 8-bit binary is left-shifted or scaled proportionally against a 1024-step resolution, common when porting code from an Arduino Uno to an ESP32.

When Line Voltage, Phase, and Power Factor Shift the Meaning

Pure binary-to-decimal math is entirely independent of AC line voltage. The binary 10110101 will always equal 181 whether you are monitoring a 120V North American branch circuit, a 230V European mains line, or a 480V 3-phase industrial motor. However, if that binary originates from an ADC sampling an AC waveform via a sensor like the ZMPT101B, the physical voltage the decimal represents shifts based on your calibration multiplier.

  • 120V vs 230V Shift: If your step-down transformer is calibrated for 120V RMS, a decimal peak count of 181 might represent 45V instantaneous. If you plug that same hardware into a 230V line without updating the software scaling factor, the physical reality is 86V, but the microcontroller will still blindly report 45V, leading to catastrophic under-reporting.
  • 3-Phase Shift: In 3-phase systems, you must track three separate binary streams offset by 120°. Converting the binary to decimal for just one phase yields the phase-to-neutral voltage, but calculating total system power requires vector math across all three decimal conversions.
  • When the Conversion is Meaningless: Converting raw binary AC waveform samples into meaningful real power (Watts) is meaningless if the phase angle and power factor (pf) are unknown. Furthermore, converting multi-byte binary registers (like a 16-bit fault code from a VFD) is meaningless if the endianness (byte order) is unknown, as swapping the high and low bytes will yield a completely different decimal.

Decision Path: Picking the Right Data Type and ADC Module

Do not default to standard int variables for embedded binary conversions. Use this decision tree to lock in the correct C++ data type and hardware module for your specific decimal range.

Condition / Decimal Range Required Data Type Recommended Hardware / Action
Decimal is 0 to 255 (e.g., 8-bit DAC or shift register) uint8_t Use MCP4725 (12-bit, but easily mapped) or 74HC595.
Decimal is 0 to 1023 (Standard 10-bit ADC) uint16_t Use Arduino Uno (ATmega328P) analogRead().
Decimal is 0 to 4095 (12-bit ADC) AND negative values are impossible uint16_t Use ESP32 DevKit v1 (Warning: avoid ADC extremes <100 and >3900 due to non-linearity).
Decimal requires high precision (16-bit) OR measures bipolar AC waveforms (negative decimals expected) int16_t (Signed) Pick: Adafruit ADS1115 (I2C 16-bit ADC, handles signed Two's complement natively).

Final Pick for Precision Mains Monitoring: If you are converting binary to decimal to measure AC voltage or current where the waveform crosses zero (requiring negative decimals), bypass the microcontroller's internal ADC entirely. Wire an ADS1115 module via I2C, declare your variable as int16_t, and read the signed decimal directly.

Frequently Asked Questions

Why does my ESP32 return erratic decimals for the same binary voltage?

The ESP32's internal 12-bit ADC is notoriously non-linear at the extremes of its range (near 0 and 4095). If your binary converts to a decimal below 100 or above 3900, the physical voltage mapping will be inaccurate. Keep your signal conditioned to read between 200 and 3800, or use an external I2C ADC like the ADS1115.

How do I handle 16-bit binary over an 8-bit I2C bus?

You must read two separate 8-bit bytes (High byte and Low byte) and combine them. Shift the high byte left by 8 bits and bitwise-OR it with the low byte: uint16_t decimal = (highByte << 8) | lowByte;. Always check the sensor datasheet to confirm if it transmits Most Significant Byte (MSB) first or Least Significant Byte (LSB) first.

Does the base-2 formula change for floating-point decimals?

Yes. If your binary represents an IEEE 754 floating-point number (common in 32-bit PLC registers), standard base-2 positional addition will yield garbage. You must use a union or a memcpy function in C++ to cast the raw 32-bit binary block directly into a float variable, allowing the compiler to handle the sign bit, exponent, and mantissa extraction.