To convert the 8-bit binary number 11010110 to denary (decimal), the direct answer is 214 (if treated as an unsigned integer) or -42 (if treated as a signed two's complement integer). The universal formula for base-2 to base-10 conversion is the sum of each bit multiplied by 2 raised to the power of its position index (starting from 0 on the right). Substituting our exact values for 11010110: (1×128) + (1×64) + (0×32) + (1×16) + (0×8) + (1×4) + (1×2) + (0×1) = 214.
However, just as calculating AC power requires knowing your voltage and phase angle, extracting a meaningful denary value from a raw binary string requires knowing the data type and register width. Below is the complete breakdown of how to execute this conversion on the bench, when the math shifts, and when raw conversion is entirely the wrong approach.
The Core Formula and Neighboring Value Reference
When reading raw hex or binary dumps from an EEPROM or a logic analyzer, you are typically looking at unsigned integers. The positional weight of each bit in an 8-bit byte doubles as you move left, from $2^0$ (1) up to $2^7$ (128).
1, your denary value is at least 128. If it is 0, the maximum possible value is 127.
To give you a quick reference for the ±20% range around our anchor value of 214, here is a spec-sheet-table of neighboring denary values and their exact 8-bit binary equivalents. This is particularly useful when calibrating PWM duty cycles or DAC outputs where a slight bit-flip drastically changes the analog output.
| Denary (Decimal) | 8-Bit Binary | Hexadecimal | Context / Shift |
|---|---|---|---|
| 171 (-20%) | 10101011 | 0xAB | Lower threshold boundary |
| 192 (-10%) | 11000000 | 0xC0 | Exactly 75% of 8-bit max |
| 214 (Target) | 11010110 | 0xD6 | Anchor calculation value |
| 235 (+10%) | 11101011 | 0xEB | Upper calibration boundary |
| 255 (Max) | 11111111 | 0xFF | Maximum 8-bit unsigned limit |
What Assumption Fixes the Answer? (Unsigned vs. Signed)
The single assumption that fixes your denary answer is signedness. Microcontrollers like the ESP32 or STM32 store negative numbers using Two's Complement. If your compiler or datasheet defines the variable as an int8_t (signed 8-bit integer) rather than a uint8_t (unsigned), the MSB is no longer worth +128; it is a sign indicator worth -128.
Let's look at how the answer shifts for our anchor 11010110 under different format assumptions:
- 8-Bit Unsigned (
uint8_t): The MSB is positive 128. Total = 214. - 8-Bit Signed (
int8_t): The MSB is negative 128. The remaining bits sum to +86. (-128 + 86) = -42. - 16-Bit Unsigned (Lower Byte): If
11010110is the lower half of a 16-bit register (e.g.,00000000 11010110), the value remains 214. - 16-Bit Unsigned (Upper Byte): If it is the upper half (
11010110 00000000), you must multiply by 256. The denary value shifts to 54,784.
Just as calculating wattage shifts drastically if you assume 120V single-phase instead of 208V 3-phase, assuming an 8-bit unsigned register when the hardware is actually outputting a 16-bit signed integer will result in completely invalid telemetry data. Always check the datasheet's register map for the exact data type before writing your bit-shift operators.
Decision Tree: Which Denary Value Do You Actually Need?
When writing firmware or parsing a serial dump, use this decision path to terminate your debugging and lock in the correct conversion method.
| Condition / Hardware Source | If True... | Concrete Pick / Action |
|---|---|---|
| Is the data from an ADC (Analog-to-Digital Converter)? | Yes | Use Unsigned. Cast to uint16_t for 12-bit/16-bit ADCs. |
| Is the data a motor encoder position or temperature delta? | Yes | Use Signed Two's Complement. Cast to int16_t or int8_t. |
| Are you reading a Real-Time Clock (RTC) like the DS3231? | Yes | STOP. Do not use raw binary conversion. Use BCD decoding (see below). |
| Is the data a raw 32-bit IEEE 754 payload from a sensor? | Yes | STOP. Use a memory union or memcpy to cast to float. |
When Binary-to-Denary Conversion is Meaningless
There are three common scenarios on the workbench where applying the standard base-2 to base-10 formula will give you a mathematically correct but practically useless denary number.
1. Binary Coded Decimal (BCD)
Many legacy and RTC chips (like the ubiquitous DS3231) store time in BCD. In BCD, each 4-bit nibble represents a single denary digit from 0 to 9. If the RTC minutes register outputs 0010 0100, treating it as raw binary yields 36. However, the actual time is 24 minutes (the upper nibble 0010 is 2, the lower 0100 is 4). If you see a 4-bit nibble containing 1010 through 1111 in a BCD register, the raw binary conversion is entirely meaningless, as those states are invalid in BCD.
2. IEEE 754 Floating Point
If you are pulling 32 bits from a high-precision I2C pressure sensor, those bits are likely formatted as an IEEE 754 single-precision float. The bits are divided into a sign bit, an 8-bit exponent, and a 23-bit mantissa. Running the standard $2^x$ summation formula on an IEEE 754 payload will yield a massive, garbage integer. You must cast the raw 32-bit integer memory block directly to a float data type in C/C++.
3. ASCII Character Encoding
If your logic analyzer captures 01000001 from a UART TX line, the raw binary conversion gives 65. But in the context of serial communication, 65 is the ASCII code for the capital letter 'A'. Converting it to a denary integer for display purposes will break your string parsing.
FAQ: Embedded Systems and Microcontroller Edge Cases
Q: How do I handle the ESP32's 12-bit ADC when converting binary to denary?
A: The ESP32 ADC oneshot API returns a raw 12-bit integer (0 to 4095). Because it exceeds the 8-bit limit, you must store the result in a uint16_t (16-bit unsigned) variable. If you accidentally store it in an 8-bit variable, the top 4 bits will be truncated, and a reading of 4000 (111110100000) will wrap around and display as 160 (10100000).
Q: Why does my bitwise shift yield a negative number when converting a 16-bit sensor reading?
A: This happens when you combine two 8-bit registers (High Byte and Low Byte) and accidentally use a signed 8-bit integer (int8_t) for the high byte before shifting. If the high byte's MSB is 1, the compiler sign-extends it during the bitwise OR operation, corrupting the full 16-bit value. Always cast your individual bytes to uint16_t before shifting and combining them.
Q: Is there a faster way to convert binary to denary in my head without writing out the powers of 2?
A: Yes. Convert the binary string to Hexadecimal first, then to denary. Group the binary into 4-bit nibbles. For 11010110, the nibbles are 1101 (13, or 'D' in hex) and 0110 (6). The hex value is 0xD6. Calculating $(13 imes 16) + 6 = 214$ is significantly faster to do mentally than summing eight individual powers of two. For deeper digital logic theory and base conversions, All About Circuits provides an excellent foundational reference.
uint16_t for raw sensor registers to prevent truncation and sign-extension bugs.






