Binary numbers are a base-2 numerical system that uses only two digits, 0 and 1, to represent all values and logic states in digital electronics. In a physical circuit, this system changes how a microcontroller's internal comparators translate analog voltage thresholds (e.g., treating anything below 0.8V as a '0' and above 2.0V as a '1') into deterministic logic for memory storage, serial communication, and GPIO control. Without binary encoding, an ESP32 or Arduino could not differentiate between a deliberate button press and transient electrical noise.

The Core Mechanism: Base-2 vs Base-10

Humans use base-10 (decimal) because we have ten fingers. Each column in a decimal number represents a power of 10: ones, tens, hundreds. Digital logic relies on base-2 because silicon transistors operate most reliably in two distinct states: cutoff (off/0) and saturation (on/1). Each column in a binary number represents a power of 2.

Bit Position7 (MSB)6543210 (LSB)
Decimal Weight1286432168421
Binary Example10101101

An 8-bit binary sequence (a byte) can represent 255 distinct positive values (from 00000000 to 11111111). When you write PORTB = 0b10101101; in C++ for an AVR microcontroller, you are physically driving specific output pins high and others low simultaneously.

Worked Numeric Example: Decoding a Byte

Let's convert the decimal number 173 into an 8-bit binary sequence. We do this by subtracting the largest possible power of 2 that fits into our remaining value, moving left to right.

  1. 128: Does 128 fit into 173? Yes. Bit 7 = 1. Remainder: 173 - 128 = 45.
  2. 64: Does 64 fit into 45? No. Bit 6 = 0. Remainder: 45.
  3. 32: Does 32 fit into 45? Yes. Bit 5 = 1. Remainder: 45 - 32 = 13.
  4. 16: Does 16 fit into 13? No. Bit 4 = 0. Remainder: 13.
  5. 8: Does 8 fit into 13? Yes. Bit 3 = 1. Remainder: 13 - 8 = 5.
  6. 4: Does 4 fit into 5? Yes. Bit 2 = 1. Remainder: 5 - 4 = 1.
  7. 2: Does 2 fit into 1? No. Bit 1 = 0. Remainder: 1.
  8. 1: Does 1 fit into 1? Yes. Bit 0 = 1. Remainder: 0.

Reading the bits from MSB to LSB, the binary representation of 173 is 10101101. If you were sending this to a 74HC595 shift register, the chip would clock these bits in one by one, ultimately latching pins Q0 through Q7 to match this exact high/low pattern.

Where You Meet Binary in Practical Electronics

You rarely write raw binary in high-level Python or JavaScript, but on the hardware bench, it is unavoidable:

  • GPIO Registers: On an Arduino Uno (ATmega328P), writing directly to the PORTD register requires an 8-bit binary mask to set pins 0-7 high or low in a single clock cycle, bypassing the overhead of digitalWrite().
  • DIP Switches: Stepper motor drivers like the A4988 use a bank of physical switches to set microstepping resolution. The switch states form a binary word that the driver's internal logic decodes.
  • I2C Addressing: The I2C bus uses 7-bit or 10-bit binary addresses to route data. A sensor and a display might share the same SDA/SCL lines, but their unique binary addresses prevent data collisions.
Bench Tip: When reading datasheets, pay attention to the 'Active-Low' designation (often marked with a bar over the pin name, like CS). In binary logic, an active-low pin executes its function when it reads a 0 (0V), not a 1.

Real-World Scenario: I2C Address Jumper Failure

Understanding binary is critical when configuring hardware addresses. Here is a common bench failure involving the popular PCA9685 16-channel PWM servo driver.

The Setup: You are building a hexapod robot using an ESP32 and two PCA9685 breakout boards on the same I2C bus. The default I2C address for the PCA9685 is 0x40 (Hexadecimal). To use two boards, you must change the address of the second board by bridging the A0 through A5 solder jumpers on the PCB, as detailed in the NXP PCA9685 datasheet.

The Numbers: You want the second board to sit at address 0x45.
Base address 0x40 in binary is 1000000.
Target address 0x45 (decimal 69) in binary is 1000101.
The lower 6 bits (A5 to A0) are 000101. This means you need to bridge jumper A0 (adds 1) and jumper A2 (adds 4) to the ground pad.

The Outcome: You solder the jumpers, wire up the I2C bus, and run an I2C scanner sketch on the ESP32. The serial monitor shows devices at 0x40 and 0x46, but nothing at 0x45. The servos on the second board remain completely unresponsive.

What Went Wrong: You confused the binary bit position with the physical pin label. You bridged A1 and A2 instead of A0 and A2.
A1 represents the 2s place (binary 000010). A2 represents the 4s place (binary 000100).
Together, they add 6 to the base address. 0x40 + 6 = 0x46. The ESP32 was pinging 0x45, but the board was listening at 0x46. Once you desoldered A1 and bridged A0, the binary math aligned, and the scanner found the board at 0x45.

Common Confusions: Binary vs. Hex and BCD

Hobbyists frequently conflate binary with other numbering systems used in digital logic. Here is how to separate them:

Hexadecimal (Base-16): Hex is not a different logic system; it is simply a human-readable shorthand for binary. Because a 4-bit binary sequence (a nibble) can represent exactly 16 values (0-15), we use the characters 0-9 and A-F to represent them. The binary 1111 is F in hex. Microcontrollers still process it as four distinct 1s and 0s.

Binary Coded Decimal (BCD): BCD is a specific encoding scheme where each decimal digit (0-9) is stored in its own 4-bit binary block. For example, decimal '45' in pure binary is 00101101. In BCD, it is 0100 0101 (4 is 0100, 5 is 0101). BCD 'wastes' the binary states from 1010 to 1111, but it is heavily used in Real-Time Clocks (like the DS3231) because it makes extracting the tens and ones digits for a display mathematically trivial.

FAQ: Binary Logic on the Bench

Q: Why do we count from 0 to 255 instead of 1 to 256 in 8-bit systems?
A: Because 00000000 (all zeros) is a valid state representing the value 0. Including zero gives you 256 total distinct states, but the maximum positive integer you can represent is 255.

Q: What is the difference between a bit and a byte?
A: A bit is a single binary digit (one transistor state, one wire voltage). A byte is a standardized grouping of 8 bits. When you buy a microcontroller with '4KB of SRAM', that means it holds 4,096 bytes, or 32,768 individual binary bits.

Q: How do I read a binary number out loud?
A: Never say 'one thousand and ten' for 1010. Read each digit individually: 'one, zero, one, zero'. This prevents confusion with decimal numbers and immediately tells the listener you are referencing a binary state or pin mask.