Converting the 8-bit binary value 10110100 yields exactly 180 in decimal and 0xB4 in hexadecimal. The formula used is the sum of each bit multiplied by 2n (where n is the position from right to left, starting at 0). Substituting our exact values: (1×27) + (0×26) + (1×25) + (1×24) + (0×23) + (1×22) + (0×21) + (0×20) = 128 + 0 + 32 + 16 + 0 + 4 + 0 + 0 = 180. For hexadecimal, split the byte into two 4-bit nibbles: 1011 (11, or B) and 0100 (4), giving 0xB4. In applied electronics, this raw number is just the starting point; its physical meaning depends entirely on your reference voltage and system architecture.
The Core Conversion Math and Neighboring Register Values
When debugging a microcontroller register or reading an 8-bit ADC (like the MCP3008 configured for 8-bit output), you rarely look at just one value. You look at the drift. Below is a reference table showing the target value (180) alongside its ±20% neighbors. This range is critical when setting software thresholds for mains voltage monitoring, where a 20% sag or swell triggers a brownout or overvoltage fault.
| Decimal | Hex | Binary (8-bit) | Variance from Target |
|---|---|---|---|
| 144 | 0x90 | 10010000 | -20% |
| 162 | 0xA2 | 10100010 | -10% |
| 180 | 0xB4 | 10110100 | Target (0%) |
| 198 | 0xC6 | 11000110 | +10% |
| 216 | 0xD8 | 11011000 | +20% |
How Binary Meaning Shifts Across 120V, 230V, and 3-Phase Mains
In pure mathematics, 180 is always 180. In electrical engineering, a binary register value is meaningless without the assumption that fixes it: the ADC reference voltage (VREF) and the physical step-down ratio. If you are reading a binary value from a sensor like the ZMPT101B voltage transformer into an ESP32, the physical voltage shifts drastically based on your mains architecture.
120V vs 230V Systems:
Assume an 8-bit ADC reading (0-255) with a 5.0V VREF. Our binary 10110100 (180) equates to an analog voltage of 3.53V (180/255 × 5.0).
If your hardware is scaled for a North American 120V RMS nominal line, that 3.53V logic-level reading might represent 118V AC at the outlet. If you deploy that exact same firmware and binary threshold to a European 230V system without changing the physical voltage divider, that same binary 180 now represents ~228V AC. The binary conversion didn't change, but the physical reality it represents shifted by a factor of nearly two.
3-Phase Systems and Power Factor:
When moving to 3-phase smart metering (using an IC like the ADE7758), binary registers accumulate active and reactive power. Here, the binary conversion becomes completely meaningless if the power factor (pf) is unknown or if the phase sequence (ABC vs ACB) is miswired. A binary register reading of 10110100 in the active energy register might indicate true power consumption, but if the pf is near zero (highly inductive motor load), the binary value in the apparent power register will be vastly different. Without the pf assumption, converting the binary watt-hour register to actual billed energy will yield garbage data.
if (adc_read > 180), write if (adc_read > 180) // 3.53V = ~118V AC on 120V line. This prevents catastrophic mistakes when porting code between 120V and 230V hardware variants.
Decision Tree: Selecting Binary Input Hardware for Mains
Reading binary states (ON/OFF) from high-voltage equipment into a low-voltage microcontroller requires isolation or level shifting. Use this decision path to select the exact component for your bench or panel build.
| Input Condition | Required Action | Concrete Hardware Pick |
|---|---|---|
| 5V TTL logic to 3.3V CMOS logic | Bi-directional level translation | SN74LVC1T45 |
| 12V PLC discrete output to 3.3V logic | Non-inverting voltage step-down | CD4050B hex buffer |
| 24V industrial proximity sensor to 3.3V logic | Opto-isolation and level shift | PC817 optocoupler (with 2.2kΩ pull-up) |
| 120V/230V AC mains binary state to 3.3V logic | High-voltage isolation and rectification | HCPL-3700 (Terminating Pick) |
The Terminating Pick: If you need to read a 120V or 230V AC binary state (like a breaker aux contact or a mains-powered limit switch) into a 3.3V GPIO, use the HCPL-3700. It is a voltage/current threshold sensing optocoupler that internally handles the AC rectification and threshold detection. You wire the mains side through a current-limiting resistor, and the output side gives you a clean, isolated binary 0 or 1 without risking your microcontroller.
When Binary Conversion Becomes Meaningless
There are three common bench scenarios where staring at a binary register will waste your time because the underlying data is invalid:
- Floating GPIO Pins: If a microcontroller pin is configured as an input but lacks a pull-down or pull-up resistor, 50/60Hz mains noise will induce random binary 1s and 0s. Converting this noise to decimal yields random numbers. Fix: Enable internal pull-downs in software or add a 10kΩ external resistor.
- Unknown VREF: If you are reading an external ADC via I2C/SPI and do not know if its VREF is tied to 3.3V, 5.0V, or an internal 1.1V bandgap, the binary-to-voltage conversion is a guess. Always verify VREF with a multimeter before trusting the binary output.
- Missing PLL Sync in AC Measurements: When sampling AC waveforms, if the Phase-Locked Loop (PLL) loses sync with the mains zero-crossing, the binary values representing the sine wave amplitude will alias. The decimal conversion is mathematically correct, but physically useless for calculating RMS voltage.
Frequently Asked Questions
Why do we use hexadecimal instead of binary in embedded C?
Hexadecimal maps perfectly to memory boundaries. One hex digit represents exactly four binary bits (a nibble). When setting an 8-bit hardware register like 0xB4, you instantly know the upper nibble is 1011 and the lower is 0100. Binary strings like 10110100 are prone to reading errors (losing your place among the 1s and 0s), while decimal (180) requires mental math to map back to the physical register bits.
How do I handle signed binary (negative numbers)?
If your sensor outputs signed data (like a bi-directional current sensor measuring AC), the 8th bit is the sign bit (Two's Complement). For an 8-bit signed integer, 10110100 is not 180. Because the MSB is 1, it is negative. To find the value: invert the bits (01001011), add 1 (01001100), and convert to decimal (76). The final value is -76. Always check the datasheet to confirm if the register is signed or unsigned before writing your conversion function.






