To map a hex value to binary using a hex chart binary lookup, split the byte into two 4-bit nibbles and map each to its binary equivalent. For example, 0x3F becomes 0011 (3) and 1111 (F), yielding 00111111. This is the foundational skill for setting GPIO masks, configuring I2C addresses, and writing to SPI registers on microcontrollers like the ESP32 or Arduino Uno.
How to Read the Hex Chart Binary Table
When working with embedded hardware, you are rarely dealing with abstract math; you are flipping physical transistor gates. The master table below is based on the NIST guidelines for binary prefixes and the ISO/IEC 80000-13 standard, which defines the 4-bit nibble as the foundational mapping unit. Because an 8-bit byte is simply two 4-bit nibbles, this 16-row table is mathematically complete. You derive any 8-bit, 16-bit, or 32-bit value by concatenating these base rows.
If you are toggling physical pins on an 8-bit shift register (like the NXP 74HC595), use the 8-bit concatenated binary column. If you are writing to a 32-bit memory-mapped register on an ESP32-WROOM-32, you must pad your 8-bit binary lookup with leading zeros to fill the 32-bit width. For example,
0x05 becomes 00000000 00000000 00000000 00000101 in the register.How bit-shifting and masking modify the base value: Just as ampacity derating rows modify the base current capacity of a wire in a conduit, bit-shifting and masking modify your base hex value before it hits the hardware. If your datasheet requires a value shifted left by 2 bits (e.g., val << 2), the base binary 00000101 (0x05) becomes 00010100 (0x14). Always apply the shift to the binary representation to visualize the physical pin states before converting back to hex for your C++ code.
The Master Hex Chart Binary Reference
The following 4-bit table is the complete master standard. No rows are hidden because no other base mappings exist in base-16 logic. To read an 8-bit value like 0xA4, look up A (1010) and 4 (0100), then combine them: 10100100.
| Hex Nibble | Binary (4-bit) | Decimal | Common GPIO Mask Equivalent |
|---|---|---|---|
| 0 | 0000 | 0 | All LOW |
| 1 | 0001 | 1 | Pin 0 HIGH |
| 2 | 0010 | 2 | Pin 1 HIGH |
| 3 | 0011 | 3 | Pins 0,1 HIGH |
| 4 | 0100 | 4 | Pin 2 HIGH |
| 5 | 0101 | 5 | Pins 0,2 HIGH |
| 6 | 0110 | 6 | Pins 1,2 HIGH |
| 7 | 0111 | 7 | Pins 0,1,2 HIGH |
| 8 | 1000 | 8 | Pin 3 HIGH |
| 9 | 1001 | 9 | Pins 0,3 HIGH |
| A | 1010 | 10 | Pins 1,3 HIGH |
| B | 1011 | 11 | Pins 0,1,3 HIGH |
| C | 1100 | 12 | Pins 2,3 HIGH |
| D | 1101 | 13 | Pins 0,2,3 HIGH |
| E | 1110 | 14 | Pins 1,2,3 HIGH |
| F | 1111 | 15 | Pins 0,1,2,3 HIGH |
Quick-Jump 8-Bit Table for Embedded Systems
While the 4-bit table above covers all mathematical possibilities, embedded engineers repeatedly query specific 8-bit bytes for I2C addressing and port manipulation. Here are the most queried 8-bit concatenations:
| Hex Byte | Binary (8-bit) | Common Embedded Use Case |
|---|---|---|
| 0x00 | 0000 0000 | Clear all GPIO pins / Null terminator |
| 0x01 | 0000 0001 | Set Pin 0 HIGH (LSB) |
| 0x3C | 0011 1100 | SSD1306 OLED I2C Address (0x78 with R/W bit) |
| 0x68 | 0110 1000 | MPU6050 IMU I2C Address (0xD0 with R/W bit) |
| 0x7F | 0111 1111 | Max positive 8-bit signed integer (127) |
| 0x80 | 1000 0000 | MSB set / Negative flag in two's complement |
| 0xA4 | 1010 0100 | Common SPI control register configuration |
| 0xFF | 1111 1111 | Set all GPIO pins HIGH / Enable internal pull-ups |
What the Table Cannot Tell You
A hex chart binary lookup is a pure mathematical translation. It lacks the hardware context required to prevent bricked boards or silent failures. Keep these three blind spots in mind:
- Endianness (Byte Order): The table maps a single byte. If you are writing a 16-bit value like
0x1234to an ESP32 register, the table won't tell you if the hardware expects Little-Endian (0x34then0x12in memory) or Big-Endian. Always check the microcontroller's technical reference manual for memory mapping rules. - Signed vs. Unsigned (Two's Complement): The binary
1111 1111is0xFF. In an unsigned 8-bit integer, this is 255. In a signed 8-bit integer (int8_t), this is -1. The table does not know your C++ variable type; your compiler does. - Active-Low Logic: Many hardware interrupts and reset pins are active-low. A binary
0on the chart means "LOW voltage," but in an active-low circuit, that0actually triggers the action (e.g., pulling the RESET pin to GND). Never assume a binary1always means "ON" without reading the datasheet's logic tables.
Hex Chart Binary FAQ
How do I convert a 16-bit hex chart binary value for ESP32 registers?
Split the 16-bit hex value into four nibbles. For example, 0x8F2C breaks down into 8, F, 2, and C. Using the master table, map them sequentially: 1000 (8), 1111 (F), 0010 (2), and 1100 (C). Concatenate them to get the 16-bit binary: 1000 1111 0010 1100. When writing this to a 32-bit ESP32 GPIO output register (like GPIO_OUT_W1TS_REG), pad the left side with sixteen zeros.
Why does my I2C hex address shift when converted to binary?
I2C addresses are typically documented as 7-bit values (e.g., 0x3C for an OLED display). However, the I2C protocol transmits 8 bits on the wire. The 8th bit (the Least Significant Bit) is the Read/Write flag. When you look up 0x3C on a hex chart binary table, you get 0011 1100. On the logic analyzer, the bus will actually transmit 0111 1000 (0x78) for a Write command, because the 7-bit address is shifted left by one bit to make room for the R/W bit. Always verify if your library expects the 7-bit or 8-bit shifted address.
What is the fastest way to read a hex chart binary mask for GPIO pins?
Memorize the powers of two in binary: 0001 (1), 0010 (2), 0100 (4), and 1000 (8). When you need to set Pin 5 HIGH, you know that is 2^5 (32 in decimal). Looking at the hex chart, 32 is 0x20, which maps to 0010 0000. Instead of doing the full conversion every time, use the C++ bitwise shift operator in your code: (1 << 5). This tells the compiler to take the binary 0000 0001 and shift it left 5 places, yielding 0010 0000 (0x20) automatically, bypassing the need for a manual lookup.






