Basic binary numbers are a base-2 numerical system using only two digits, 0 and 1, to represent all data, memory addresses, and logic states in digital electronics. When you write digitalWrite(13, HIGH) on an Arduino or configure a GPIO pin on an ESP32, you are not just changing a software variable; you are manipulating a single binary digit (bit) that physically connects a voltage rail to a silicon gate. Think of a binary digit as a single mechanical light switch on a wall—it is either physically OFF (0) or ON (1), with no dimmer in between.
The Core Mechanism: Base-2 vs. Base-10
In the decimal (base-10) system, each column represents a power of 10 (1s, 10s, 100s). In binary (base-2), each column represents a power of 2 (1s, 2s, 4s, 8s, 16s, etc.). Microcontrollers process data in 8-bit, 16-bit, or 32-bit chunks. An 8-bit chunk (a byte) can represent any decimal value from 0 to 255.
Let us look at a worked numeric example using a common component: the 74HC595 8-bit shift register. Suppose your microcontroller needs to turn on a specific pattern of LEDs, and the required decimal value is 173. To send this to the shift register, the microcontroller must convert 173 into an 8-bit binary sequence.
173 = (1×128) + (0×64) + (1×32) + (0×16) + (1×8) + (1×4) + (0×2) + (1×1)
Binary Result: 10101101
When the ESP32 clocks this data into the 74HC595 via SPI or bit-banging, the physical output pins (QA through QH) will latch to the following states:
| Bit Position | Power of 2 | Binary Digit | 74HC595 Pin | Physical Output State |
|---|---|---|---|---|
| MSB (Bit 7) | 128 | 1 | QH | HIGH (VCC) |
| Bit 6 | 64 | 0 | QG | LOW (GND) |
| Bit 5 | 32 | 1 | QF | HIGH (VCC) |
| Bit 4 | 16 | 0 | QE | LOW (GND) |
| Bit 3 | 8 | 1 | QD | HIGH (VCC) |
| Bit 2 | 4 | 1 | QC | HIGH (VCC) |
| Bit 1 | 2 | 0 | QB | LOW (GND) |
| LSB (Bit 0) | 1 | 1 | QA | HIGH (VCC) |
This exact translation from abstract math to physical pin states is the foundation of all embedded systems. For a deeper mathematical breakdown of base conversions, the All About Circuits digital textbook provides an excellent reference on positional weightings.
What Binary Changes in a Real Circuit
A common misconception is that binary numbers are purely abstract software concepts. In a real circuit, a binary 0 or 1 dictates physical voltage thresholds that drive current through transistors. What changes in the hardware is the biasing of CMOS (Complementary Metal-Oxide-Semiconductor) gates.
Take the Texas Instruments SN74HC595 datasheet as a benchmark. When operating at a 5V supply (VCC = 5V), the IC does not just look for 'exactly 0V' or 'exactly 5V'. It uses specific threshold windows:
- Logic LOW (Binary 0): Guaranteed recognized between 0V and 1.5V (VIL).
- Logic HIGH (Binary 1): Guaranteed recognized between 3.5V and 5V (VIH).
Therefore, binary numbers govern the strict timing and voltage edges required to keep digital signals cleanly inside the 0V or 5V rails, avoiding the undefined analog middle-ground.
Where You Meet Basic Binary Numbers in Practice
If you build circuits on a workbench, you will interact with binary hardware configurations constantly. Here are the three most common physical manifestations:
1. I2C Address Configuration Pins
Many I2C sensors and I/O expanders, like the PCF8574, feature physical pins labeled A0, A1, and A2. These pins act as hardware binary inputs to set the device's I2C bus address. The base address might be 0x20 (binary 0100000). If you wire A0 to VCC (1), A1 to GND (0), and A2 to VCC (1), you are adding the binary value 101 (decimal 5) to the base address. The microcontroller must now poll address 0x25 to talk to that specific chip.
2. DIP Switches and Pull-Up Resistors
Industrial motor drivers and stepper controllers (like the DM542T) use banks of DIP switches to set the RMS current limit and microstepping resolution. Each switch is a physical binary bit. Because a floating pin can pick up electromagnetic interference (EMI) and read as a random 1 or 0, these switches are always wired with pull-down or pull-up resistors (typically 10kΩ) to firmly anchor the binary 0 state to GND.
3. Bitmasking in Embedded C/C++
When reading a fault register from a Battery Management System (BMS) via SPI, you receive an 8-bit byte. If bit 3 indicates an over-temperature fault, you do not convert the whole byte to decimal. You use a binary bitmask: if (register_data & (1 << 3)). This isolates the 3rd binary digit without disturbing the rest of the byte. The Espressif ESP-IDF GPIO documentation relies heavily on this exact binary bitmasking technique for configuring pin direction and interrupt matrices.
Common Confusions: Binary vs. Hexadecimal vs. BCD
People frequently confuse basic binary numbers with hexadecimal and Binary-Coded Decimal (BCD). Understanding the difference prevents critical errors when reading logic analyzer traces or writing driver code.
| System | Base | Characters Used | Primary Use Case in Electronics |
|---|---|---|---|
| Binary | Base-2 | 0, 1 | Physical logic states, bitmasking, shift registers. |
| Hexadecimal | Base-16 | 0-9, A-F | Human-readable shorthand for binary memory addresses and color codes. |
| BCD | Base-10 (via 4-bit binary) | 0000 to 1001 | Driving 7-segment displays, real-time clocks (RTCs like DS3231). |
Hexadecimal is not a different physical state; it is simply a human-friendly wrapper. The binary byte 11111111 is hard to read at a glance, so we group it into two 4-bit nibbles and call it 0xFF. BCD, however, is a distinct encoding scheme. In BCD, the decimal number 59 is stored as 0101 1001 (5 and 9 separated), whereas in pure binary, 59 is 00111011. If you send pure binary 59 to a BCD-encoded 7-segment decoder, the display will show garbage characters.
Frequently Asked Questions
How do basic binary numbers dictate PWM duty cycles on a microcontroller?
Pulse Width Modulation (PWM) relies on binary timers. An 8-bit hardware timer on an ATmega328P (Arduino Uno) counts in binary from 00000000 (0) to 11111111 (255). When you set analogWrite(pin, 127), you are loading the binary value 01111111 into the timer's compare register. The hardware output pin stays HIGH until the timer's binary count matches 127, then it flips LOW. The binary resolution directly dictates your duty cycle granularity (in this case, steps of roughly 0.39%).
Why do logic analyzers show basic binary numbers as square waves instead of numbers?
A logic analyzer does not 'know' what a number is; it only measures voltage thresholds over time. It samples the physical voltage on a wire at a set frequency (e.g., 24 MHz). If the voltage crosses the VIH threshold (e.g., 2.0V on a 3.3V system), the analyzer plots a HIGH square wave (binary 1). If it drops below VIL, it plots a LOW square wave (binary 0). The software on your PC then groups those square waves into 8-bit or 16-bit chunks and translates them into decimal or hex numbers for your convenience.
What is the difference between basic binary numbers and two's complement in embedded C?
Basic binary numbers (unsigned) can only represent positive values (0 to 255 for 8 bits). Two's complement is a mathematical trick used to represent negative numbers in binary by inverting the bits and adding 1. In an 8-bit signed integer (int8_t), the binary 11111111 does not mean 255; it means -1. The Most Significant Bit (MSB) acts as a negative sign flag. When reading raw sensor data (like temperature from an MPU6050 accelerometer), failing to cast the binary register data to a signed type will result in massive, incorrect positive numbers when the sensor reads below zero.






