To answer how to convert a binary number into decimal directly: the 8-bit binary sequence 11010110 converts to 214 in standard unsigned decimal, but -42 if interpreted as a signed two's complement integer. The foundational formula is D = Σ(bi × 2i). Substituting our values for 11010110 (reading right-to-left from bit 0): (0×1) + (1×2) + (1×4) + (0×8) + (1×16) + (0×32) + (1×64) + (1×128) = 214. Whether you are parsing a raw I2C register dump from an ESP32-S3 or debugging a microcontroller fault code, knowing the exact decimal equivalent—and the data type assumptions behind it—is the critical first step.
Step-by-Step Substitution and Neighboring Values
The base-2 positional system assigns a weight to each bit based on its index, starting at 0 on the far right. When you map a binary string to a base-10 integer, you are simply summing the weights of the '1' bits. For our target value 11010110, the active bits are at positions 1, 2, 4, 6, and 7. Summing those powers of two (2 + 4 + 16 + 64 + 128) yields 214.
When debugging digital logic or reviewing hex dumps, it helps to see the surrounding neighborhood. Below is a reference table covering a ±20% range around our target decimal value (172 to 250), showing how the binary shifts and how the signed two's complement interpretation behaves concurrently.
| Binary (8-bit) | Unsigned Decimal | Signed Decimal (Two's Complement) | Hex Equivalent |
|---|---|---|---|
| 10101100 | 172 | -84 | 0xAC |
| 10111000 | 184 | -72 | 0xB8 |
| 11000100 | 196 | -60 | 0xC4 |
| 11010000 | 208 | -48 | 0xD0 |
| 11010110 | 214 | -42 | 0xD6 |
| 11100010 | 226 | -30 | 0xE2 |
| 11101110 | 238 | -18 | 0xEE |
| 11111010 | 250 | -6 | 0xFA |
Reference Table: Powers of Two (Bit 0 to Bit 15)
Memorizing every power of two is unnecessary, but having a quick-reference spec sheet on your bench saves time when you are manually masking bits or calculating ADC resolution limits. The table below covers the first 16 bits, which encompasses the standard 8-bit and 16-bit registers found on most AVR, PIC, and ARM Cortex-M microcontrollers.
| Bit Position (i) | Power of 2 (2i) | Decimal Weight | Hex Mask |
|---|---|---|---|
| 0 | 20 | 1 | 0x0001 |
| 1 | 21 | 2 | 0x0002 |
| 2 | 22 | 4 | 0x0004 |
| 3 | 23 | 8 | 0x0008 |
| 4 | 24 | 16 | 0x0010 |
| 5 | 25 | 32 | 0x0020 |
| 6 | 26 | 64 | 0x0040 |
| 7 | 27 | 128 | 0x0080 |
| 8 | 28 | 256 | 0x0100 |
| 9 | 29 | 512 | 0x0200 |
| 10 | 210 | 1,024 | 0x0400 |
| 11 | 211 | 2,048 | 0x0800 |
| 12 | 212 | 4,096 | 0x1000 |
| 13 | 213 | 8,192 | 0x2000 |
| 14 | 214 | 16,384 | 0x4000 |
| 15 | 215 | 32,768 | 0x8000 |
For deeper digital logic fundamentals, refer to resources like the Khan Academy Binary Numbers module.
Assumptions That Fix Your Answer (Signed vs. Unsigned & Bit-Width)
In AC power calculations, your answer shifts depending on whether you assume 120V single-phase or 208V three-phase. In binary conversion, the equivalent assumption that fixes your answer is the data type definition (unsigned vs. signed) and the bit-width (8-bit vs. 16-bit vs. 32-bit). A raw string of 1s and 0s has no inherent numerical meaning until the system's architecture defines how to read it.
How the Answer Shifts Across Representations
If you pull the byte 11010110 from a sensor register, the decimal output shifts drastically based on how your C/C++ code casts the variable:
| Representation | Binary Input | Decimal Output | Core Assumption |
|---|---|---|---|
8-bit Unsigned (uint8_t) | 11010110 | 214 | All bits are positive weights. Range: 0 to 255. |
8-bit Signed (int8_t) | 11010110 | -42 | MSB (Bit 7) is the sign bit. Uses Two's Complement. Range: -128 to 127. |
16-bit Unsigned (uint16_t) | 00000000 11010110 | 214 | Padded to 16 bits. The value remains positive and identical. |
16-bit Signed (int16_t) | 00000000 11010110 | 214 | MSB (Bit 15) is 0, so it is read as a positive integer. |
When the Conversion is Meaningless
Blindly applying the base-2 integer formula yields garbage data if the binary string represents encoded formats rather than raw integers. The conversion is mathematically valid but practically meaningless in these scenarios:
- IEEE 754 Floating-Point: If your 32-bit binary sequence represents a float (as defined by the IEEE 754 Standard), the bits are split into a sign bit, an 8-bit exponent, and a 23-bit mantissa. Summing them as positional powers of two will give you a massive, incorrect integer instead of the actual decimal fraction (e.g.,
01000000100100100000000000000000is 4.5625 in float, not 1,083,244,544). - Binary-Coded Decimal (BCD): In BCD, each 4-bit nibble represents a single decimal digit (0-9). The binary
1001 0110in BCD means '96', but standard base-2 conversion yields 150. - ASCII / UTF-8 Text: The byte
01000001converts to 65 in decimal, but in a serial terminal, it represents the uppercase character 'A'.
FAQ: Binary to Decimal Edge Cases
Can I convert fractional binary numbers into decimal?
Yes. The formula extends to the right of the binary point using negative powers of two. For example, 101.11 converts to (1×4) + (0×2) + (1×1) + (1×0.5) + (1×0.25) = 5.75 in decimal.
Does endianness change the decimal conversion?
Endianness (Big-Endian vs. Little-Endian) only matters when you are combining multiple bytes into a larger integer (like combining two 8-bit registers into a 16-bit value). For a single, isolated binary string, endianness does not apply; you always read the least significant bit (LSB) on the far right.
Why does my microcontroller print a negative number for a large sensor reading?
You are likely experiencing an overflow or a signed-casting error. If a sensor outputs an unsigned 8-bit value of 214 (11010110), but your code stores it in a signed 8-bit integer (int8_t), the compiler reads the leading '1' as a negative sign bit, instantly converting your 214 into -42. Always match your variable types to the sensor's datasheet specifications.






