Binary numbers are a base-2 numeral system that represents all values using only two states, typically 0 (low voltage/off) and 1 (high voltage/on). In a real circuit or installation, this base-2 math dictates how microcontrollers process ADC sensor data, how shift registers multiplex output pins, and how digital logic gates evaluate truth tables. When consulting a binary numbers wiki for embedded systems, makers most commonly confuse abstract binary values with Binary-Coded Decimal (BCD), or they conflate bitwise operations (like & and |) with standard logical boolean operators in C++.
The Core Mechanics: Base-2 Place Values and Conversion
Unlike the decimal (base-10) system you use for everyday math, where each column represents a power of 10 (ones, tens, hundreds), binary uses powers of 2. Each column—called a bit—can only hold a 0 or a 1. An 8-bit sequence (a byte) is the standard unit of data in most microcontrollers, giving you 256 possible states (0 through 255).
| Bit Position | 7 (MSB) | 6 | 5 | 4 | 3 | 2 | 1 | 0 (LSB) |
|---|---|---|---|---|---|---|---|---|
| Decimal Weight | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Example Byte | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
Worked Numeric Example: Reading an I2C Expander
Suppose you are reading an 8-bit status byte from an I2C GPIO expander like the MCP23008, and the returned byte is 11010010. To find out what this means in decimal, you add the weights of the columns where the bit is a 1:
- Bit 7 (128) + Bit 6 (64) + Bit 4 (16) + Bit 1 (2)
- 128 + 64 + 16 + 2 = 210
In hexadecimal, this is 0xD2. If you are mapping this to physical pins on the expander, pins 7, 6, 4, and 1 are currently reading HIGH, while the rest are LOW. Understanding this conversion is critical when debugging sensor registers via the Serial Monitor.
Where You Meet Binary in Practical Electronics
You don't just use binary in abstract math; it directly controls physical hardware behavior on your workbench.
Shift Registers and Pin Multiplexing
When you run out of GPIO pins on an Arduino or ESP32, you use a shift register like the TI SN74HC595. You send a single byte over SPI to control 8 separate output pins. If you want to turn on LEDs connected to pins Q0, Q2, and Q7, you construct the binary number 10000101 (decimal 133) and shift it out. The hardware physically latches these 8 bits to the output transistors simultaneously.
Direct Port Manipulation
Using digitalWrite() in Arduino takes roughly 50 clock cycles per pin. If you need to toggle six pins at the exact same microsecond for a high-speed ADC interface, you write directly to the hardware port register using binary notation. According to the Arduino Port Manipulation Reference, setting PORTB = B11010010; on an ATmega328P instantly forces pins 8 through 13 into the exact HIGH/LOW states defined by that byte, executing in a single clock cycle.
A logical
1 does not universally mean 5 volts. On a 5V Arduino Uno, a 1 is ~5V. On an ESP32, a 1 is 3.3V. On a modern 1.8V logic sensor, it is 1.8V. The binary number is the mathematical abstraction; the voltage threshold (V_IH and V_IL in the datasheet) is the physical reality. Never connect a 5V logic 1 directly to a 3.3V ESP32 input without a level shifter, or you will fry the GPIO pad.
Bitwise Operations vs. Logical Operations
A frequent trap for hobbyists moving from basic scripting to embedded C++ is confusing logical operators with bitwise operators. Logical operators evaluate the entire expression as true or false. Bitwise operators evaluate each individual bit in the binary word independently.
| Operator | Name | Bitwise Function | Common Use Case |
|---|---|---|---|
& |
AND | Outputs 1 only if both bits are 1 | Masking (checking if a specific pin is HIGH) |
| |
OR | Outputs 1 if either bit is 1 | Setting a specific bit HIGH without changing others |
^ |
XOR | Outputs 1 if bits are different | Toggling a bit (flipping an LED state) |
~ |
NOT | Inverts all bits (0 becomes 1, 1 becomes 0) | Creating inverse masks or handling active-low signals |
Practical Example: You have a status byte 11010010 and you only want to know if Bit 2 (the interrupt flag) is set. You use a bitwise AND mask:
11010010 & 00000100 results in 00000000 (False). Bit 2 is LOW. If the byte was 11010110, the mask would yield 00000100 (True), telling your code to trigger the interrupt routine. For a deeper dive into how these gates physically operate in silicon, the All About Circuits digital textbook provides excellent schematic-level breakdowns.
Binary Numbers Wiki FAQ
Why do microcontrollers use binary instead of decimal?
Microcontrollers are built from billions of microscopic transistors that act as switches. A switch only has two reliable physical states: fully off (cutoff) and fully on (saturation). To use a base-10 decimal system natively in silicon, a single transistor gate would need to reliably distinguish between 10 different, tightly spaced voltage levels (e.g., 0.5V, 1.0V, 1.5V). This would require complex, power-hungry digital-to-analog circuitry for every single logic gate and would be incredibly susceptible to electrical noise and voltage drop. Base-2 binary is robust, noise-immune, and cheap to manufacture.
What is the difference between binary and Binary-Coded Decimal (BCD)?
Standard binary counts continuously up to its bit limit; an 8-bit binary number can represent 0 to 255. Binary-Coded Decimal (BCD) restricts groups of 4 bits (nibbles) to only represent the decimal digits 0 through 9. For example, the decimal number 15 in standard binary is 00001111. In BCD, it is split into two digits (1 and 5), resulting in 0001 0101. You will frequently encounter BCD when reading time and date registers from Real-Time Clock (RTC) modules like the DS3231, which store hours, minutes, and seconds in BCD format to simplify driving 7-segment displays.
How do I read a binary number quickly without a calculator?
The fastest method for embedded developers is the "nibble-to-hex" translation. Instead of adding up powers of 2 across an 8-bit or 16-bit string, split the binary number into 4-bit chunks (nibbles). Memorize the hex equivalents for 0-15 (e.g., 1010 is A, 1100 is C, 0101 is 5). If you see 11010010, split it into 1101 (13, or D) and 0010 (2). You instantly know the hex value is 0xD2. From there, converting to decimal is standard base-16 math: (13 × 16) + 2 = 210.
Does a logical 1 always mean the device is "On"?
No. In many robust industrial and automotive circuits, signals are active-low. This means a logical 0 (0V / Ground) triggers the action, while a logical 1 (High Voltage) is the idle or "off" state. This is done for noise immunity and safety; if a wire breaks or a microcontroller resets and pins float high, the system safely defaults to the off state. Always check the datasheet for a bar over the pin name (e.g., RESET or CS), which indicates the pin is active-low and requires a logical 0 to trigger.






