A hexadecimal and binary table maps base-16 (hex) and base-2 (binary) values to base-10 (decimal) for digital logic, memory addressing, and embedded firmware. If you are configuring an ESP32 GPIO register, decoding an I2C sensor payload, or setting a PWM duty cycle, you need to know exactly what 0x55 or 0b01010101 means in physical voltage states. Use binary for individual pin mapping and bitwise toggles, and use hexadecimal for byte-level register masks, memory pointers, and communication addresses.
The Complete Hexadecimal and Binary Reference Table
This table provides the fundamental 4-bit nibble mappings (0x0 to 0xF) alongside the most queried 8-bit byte boundaries and standard test patterns. Bookmark this page and use the quick-jump IDs (like #row-0x55) to navigate directly to your target value.
How to read this table: The Decimal column is your human-readable baseline. The Hex column (prefixed with 0x) is used for memory addresses and I2C/SPI commands. The Binary column (prefixed with 0b) shows the exact physical state of 4 or 8 hardware pins (1 = HIGH/3.3V, 0 = LOW/GND). The Common Embedded Use column tells you where this specific value appears in real-world microcontroller datasheets.
| Decimal | Hex (4-bit / 8-bit) | Binary | Common Embedded Use |
|---|---|---|---|
| 0 | 0x0 / 0x00 | 0000 / 00000000 | Clear register, Pull-down state, NULL pointer |
| 1 | 0x1 / 0x01 | 0001 / 00000001 | Bit 0 mask, Enable flag, LSB toggle |
| 2 | 0x2 / 0x02 | 0010 / 00000010 | Bit 1 mask, I2C read/write bit shift |
| 3 | 0x3 / 0x03 | 0011 / 00000011 | Lower nibble mask (Bits 0-1) |
| 4 | 0x4 / 0x04 | 0100 / 00000100 | Bit 2 mask, UART stop bit configuration |
| 5 | 0x5 / 0x05 | 0101 / 00000101 | Alternating bit pattern (partial) |
| 7 | 0x7 / 0x07 | 0111 / 00000111 | 3-bit mask (Bits 0-2), SPI clock divider |
| 8 | 0x8 / 0x08 | 1000 / 00001000 | Bit 3 mask, MSB of a nibble |
| 10 | 0xA / 0x0A | 1010 / 00001010 | Hex 'A', common BCD (Binary Coded Decimal) |
| 15 | 0xF / 0x0F | 1111 / 00001111 | Full nibble mask, lower 4-bit extraction |
| 16 | 0x10 | 00010000 | Bit 4 mask, 16-byte buffer boundary |
| 32 | 0x20 | 00100000 | Bit 5 mask, 32-bit register boundary (ESP32) |
| 64 | 0x40 | 01000000 | Bit 6 mask, 64-byte cache line size |
| 85 | 0x55 | 01010101 | Alternating 0/1 test pattern (RAM testing) |
| 127 | 0x7F | 01111111 | Max positive 8-bit signed integer (Two's complement) |
| 128 | 0x80 | 10000000 | Bit 7 mask (MSB), Sign bit in signed integers |
| 170 | 0xAA | 10101010 | Alternating 1/0 test pattern (Bus contention test) |
| 255 | 0xFF | 11111111 | Full byte mask, Max 8-bit unsigned, Pull-up state |
Which Column Applies to Your Hardware Installation
Just as an electrical panel schedule dictates which wire color goes to which breaker, your specific hardware task dictates which column of the hexadecimal and binary table you must use. Using the wrong base leads to unreadable code and silent register misconfigurations.
- The Binary Column (
0b): Use this when your 'installation' involves direct GPIO pin mapping or single-bit toggles. If you are setting up an ESP32 pin matrix where Bit 0 is SDA and Bit 1 is SCL, writing0b00000011makes the physical pin states instantly visible to the human eye. Espressif's GPIO documentation heavily relies on binary masks for pin routing. - The Hexadecimal Column (
0x): Use this for I2C addresses, SPI command bytes, memory pointers, and multi-byte register configurations. If you are configuring a sensor with an I2C address of 104 (decimal), writing0x68is the industry standard. It groups perfectly into 4-bit nibbles, making it easier to spot errors than a long string of 1s and 0s. - The Decimal Column: Reserve this for human-scale physical quantities: PWM duty cycles (e.g., 50% brightness), ADC voltage thresholds (e.g., 2048 for mid-scale on a 12-bit ADC), and baud rates (e.g., 115200).
How Bit-Shifting and Masking Modify Base Values
In wire sizing, ampacity derating rows modify the base current capacity based on ambient temperature and conduit fill. In digital logic, bit-shifting and masking modify the base binary value based on register position and bus width. A static 0x01 in the table means 'Bit 0 HIGH', but in your firmware, that value is rarely used without modification.
Here is how shifting alters the base table values:
- Left Shift (
<<): If you need to set Bit 4 HIGH, you don't look up '16' in the table. You take the base value0x01(or0b00000001) and shift it:1 << 4. The binary becomes00010000(Hex0x10, Decimal 16). This is how microcontroller HAL (Hardware Abstraction Layer) libraries define pin masks dynamically. - Bitwise AND Masking (
&): To extract the lower nibble of an incoming I2C byte, you apply a mask from the table. If the incoming byte is0xB7(10110111), applying the0x0Fmask (00001111) via0xB7 & 0x0Fzeroes out the top four bits, leaving exactly0x07. - Bitwise OR Setting (
|): To force Bit 7 HIGH without disturbing the other 7 bits in a control register, you OR the current register value with the0x80mask from the table.
Decision Tree: Selecting the Right Numeral Base
Do not mix numeral bases arbitrarily. Use this decision path to determine the exact format for your next line of embedded C/C++ or MicroPython code.
| If your task involves... | And the value represents... | Then use this format (Concrete Pick) |
|---|---|---|
| Single GPIO pin state or direct physical pin mapping | On/Off, High/Low, 1 or 0 | Binary (0b1 or 0b0) |
| Multi-pin port configuration (e.g., 8-bit LCD data bus) | A specific combination of pin states | Binary (0b10100101) |
| I2C sensor address, SPI command, or MAC address byte | A protocol-defined identifier or instruction | Hexadecimal (0x68, 0x55) |
| Memory pointer, DMA buffer address, or register offset | A location in the microcontroller's memory map | Hexadecimal (0x3FF44000) |
| PWM duty cycle, ADC threshold, or timer period | A physical quantity, percentage, or time interval | Decimal (128, 4096) |
| Configuring a 32-bit hardware register with multiple bitfields | A complex mix of flags, dividers, and enables | Hexadecimal (0x) combined with << shifts |
Default Pick: If you are ever in doubt while writing low-level register configuration code, default to Hexadecimal (0x). It is the universal language of microcontroller datasheets (from TI, STMicroelectronics, and Espressif) and maps cleanly to both 8-bit bytes and 32-bit words without the visual clutter of 32-character binary strings.
What This Table Cannot Tell You (Edge Cases and Limits)
A static conversion table assumes unsigned, big-endian, positive integers. Real-world firmware debugging requires understanding what the table hides. According to standard digital logic principles outlined in resources like All About Circuits' Digital Textbook, you must account for the following edge cases:
1. Signed Integers and Two's Complement
The table shows 0xFF as 255. This is true for an unsigned char (8-bit unsigned integer). However, if your variable is declared as a signed 8-bit integer (int8_t), 0xFF represents -1. The MSB (Bit 7, or 0x80) acts as the sign bit. If you are reading temperature data from an I2C sensor like the BMP280, a raw hex value of 0xF0 is not +240; it is -16. Always check the sensor datasheet to confirm if the payload is signed or unsigned before casting the hex value.
2. Endianness (Byte Order in Memory)
The table maps a single byte. But when you write a 16-bit or 32-bit hex value to memory, the order of the bytes depends on the microcontroller's architecture. The ESP32 (Xtensa LX6) and most ARM Cortex-M chips (STM32, RP2040) are Little-Endian. This means the least significant byte is stored at the lowest memory address. If you write the 32-bit hex value 0x12345678 to a memory buffer, it is physically stored in RAM as 0x78, 0x56, 0x34, 0x12. If you transmit this buffer over UART without accounting for endianness, the receiving device will read it backward.
3. Floating-Point Representation (IEEE 754)
You cannot use this table to map floating-point numbers (e.g., 3.14) to hex. Floating-point values follow the IEEE 754 standard, which splits the 32 bits into a sign bit, an 8-bit exponent, and a 23-bit mantissa. The hex representation of 3.14f is 0x4048F5C3, which looks nothing like the integer '3'. If you need to send a float over an I2C bus, cast it to a byte array using a union or memcpy in C, rather than attempting manual hex conversion.






