Binary is a base-2 numbering system using only 0s and 1s to represent values, where each digit's position signifies an increasing power of two. When makers and engineers need to map physical logic states to decimal values, knowing how to count 1-10 in binary is the foundational step for programming GPIO pins, configuring shift registers, and debugging digital logic circuits. In a real circuit, this numbering system changes how we route physical traces, configure pull-up/pull-down resistors, and interpret 5V or 3.3V signals on an oscilloscope. What people most commonly confuse is the bit index (the physical pin number, 0-3) with the bit weight (the mathematical value that pin represents, 1, 2, 4, 8).
The 1-10 in Binary Reference Chart
Before writing firmware or wiring a breadboard, you need a reliable lookup reference. The table below maps the decimal numbers 1 through 10 to their 4-bit binary equivalents, hexadecimal representations, and the physical logic states required on a standard 4-bit port. Read the 'Logic States' columns from left to right as Q3 (Most Significant Bit) down to Q0 (Least Significant Bit).
| Decimal | 4-Bit Binary | Hex | Q3 (Weight 8) | Q2 (Weight 4) | Q1 (Weight 2) | Q0 (Weight 1) |
|---|---|---|---|---|---|---|
| 1 | 0001 | 0x01 | LOW | LOW | LOW | HIGH |
| 2 | 0010 | 0x02 | LOW | LOW | HIGH | LOW |
| 3 | 0011 | 0x03 | LOW | LOW | HIGH | HIGH |
| 4 | 0100 | 0x04 | LOW | HIGH | LOW | LOW |
| 5 | 0101 | 0x05 | LOW | HIGH | LOW | HIGH |
| 6 | 0110 | 0x06 | LOW | HIGH | HIGH | LOW |
| 7 | 0111 | 0x07 | LOW | HIGH | HIGH | HIGH |
| 8 | 1000 | 0x08 | HIGH | LOW | LOW | LOW |
| 9 | 1001 | 0x09 | HIGH | LOW | LOW | HIGH |
| 10 | 1010 | 0x0A | HIGH | LOW | HIGH | LOW |
Worked Example: Mapping Decimal 7 to an ESP32 Port
Let us move from theory to the workbench. Suppose you are building a custom control panel with an ESP32 DevKit V1 and need to output the decimal number 7 to a 4-bit LED bar graph. You have assigned the following GPIO pins to your 4-bit port:
- GPIO 25: Q0 (Least Significant Bit, Weight 1)
- GPIO 26: Q1 (Weight 2)
- GPIO 27: Q2 (Weight 4)
- GPIO 14: Q3 (Most Significant Bit, Weight 8)
Looking at our reference chart, decimal 7 is 0111 in binary. This means the 8-weight bit is 0, and the 4, 2, and 1-weight bits are all 1s. Here is exactly how you configure the hardware and firmware:
- Calculate the Logic States: Q3 (GPIO 14) must be LOW (0V). Q2 (GPIO 27), Q1 (GPIO 26), and Q0 (GPIO 25) must be HIGH (3.3V).
- Set Pin Modes: In your
setup()function, configure all four pins asOUTPUT. - Write the States: Use
digitalWrite()or direct port manipulation to set GPIO 14 toLOW, and GPIOs 25, 26, and 27 toHIGH.
digitalWrite calls, advanced firmware engineers group these pins into a single hardware register. If mapped to the same port register, writing the hexadecimal value 0x07 directly to the port output register updates all four pins in a single clock cycle, eliminating microsecond-level timing skew between the LEDs turning on.
Where You Meet Binary Counting in Physical Circuits
You rarely count 1-10 in binary just to light up LEDs. In professional and advanced hobbyist installations, binary counting dictates how hardware components interpret configuration commands.
1. Shift Registers (e.g., 74HC595)
When you run out of GPIO pins, you use a shift register like the Texas Instruments SN74HC595. To output decimal 7, your microcontroller shifts the bits in serially. The ESP32 sends a '1' to the SER (Serial Input) pin, pulses the SRCLK (Shift Register Clock), and repeats. Once all 8 bits are shifted into the internal storage register, a single pulse on the RCLK (Storage Register Clock) pin latches the data to the output pins (QA through QH). If you send 0x07, the first three output pins go HIGH, and the rest stay LOW.
2. Stepper Driver Microstepping (e.g., A4988)
If you are building a CNC router or a 3D printer, you will use stepper motor drivers like the Pololu A4988. The microstepping resolution is configured via three physical pins: MS1, MS2, and MS3. These pins read binary logic to determine the stepping mode. To achieve 1/8th microstepping, you must set the pins to binary 011 (Decimal 3): MS1 HIGH, MS2 HIGH, MS3 LOW. To achieve 1/16th microstepping, you set them to binary 111 (Decimal 7): all three pins HIGH. Miswiring these binary states will cause your motor to run at the wrong speed or vibrate violently due to mismatched step pulses.
3. DMX512 Lighting Addresses
In stage lighting, DMX512 fixtures use a block of 9 DIP switches to set their starting address. While the full address goes up to 512, the first 10 switches represent binary weights 1, 2, 4, 8, 16, 32, 64, 128, and 256. If you need to set a fixture to DMX address 10, you flip switch 2 (weight 8) and switch 4 (weight 2) to the ON position, leaving the rest OFF. Understanding the 1-10 binary foundation is mandatory before scaling up to 9-bit addressing.
Common Pitfalls: Endianness and Bit Weight Confusion
Even experienced engineers make wiring mistakes when translating binary to physical hardware. Here is a troubleshooting FAQ for the most common binary-counting errors encountered on the bench.
Why is my LED bar graph counting backwards?
The Cause: You have reversed your Most Significant Bit (MSB) and Least Significant Bit (LSB) wiring. If your firmware sends decimal 1 (0001), but you wired the Q0 pin to the physical MSB LED, the hardware interprets it as 1000 (decimal 8).
The Fix: Check your ribbon cable orientation. If using a 10-pin IDC ribbon cable, ensure the red stripe (Pin 1) aligns with the Q0/LSB pin on your microcontroller and the corresponding LSB pin on your display driver. Do not rely on physical left-to-right layout; always trace the net to the specific pin silkscreen.
Why does my code use '1 << 3' instead of just writing '8'?
The Cause: This is a bitwise operation used to prevent human error. '1 << 3' means 'take the binary number 1 and shift it left by 3 positions', which results in 1000 (decimal 8).
The Fix: Adopt this syntax in your firmware. Writing PORTB |= (1 << PB3) explicitly tells the compiler (and the next engineer reading your code) that you are targeting the physical pin index 3, rather than relying on the reader to mentally convert decimal 8 to binary on the fly.
My multimeter reads 1.2V on a pin that should be HIGH (5V). What is wrong?
The Cause: You are likely measuring a pin that is being rapidly toggled between HIGH and LOW via Pulse Width Modulation (PWM), or you are measuring a floating input pin that is picking up ambient electromagnetic noise.
The Fix: If the pin is supposed to be a static binary output (like a shift register latch), ensure your code isn't accidentally running a PWM routine on that specific timer channel. If it is an input pin (like an unconnected MS3 pin on a stepper driver), install a 10kΩ pull-up resistor to VCC to force a solid 5V HIGH state.
Mastering the translation from decimal 1-10 into binary logic states is not just an academic exercise. It is the exact mechanism by which software commands become physical voltage levels. Whether you are addressing a DMX lighting rig, configuring a stepper driver, or debugging a shift register daisy-chain, verifying your bit weights and pin mappings with a multimeter will save you hours of frustrating troubleshooting.






