Coding 101

Mastering Hex Codes: Complete Hexadecimal, Binary, ASCII Lookup Table, and Modern CSS Color Spaces

DD
Ankur Ishwar
14 min read Updated Sep 6, 2026
Hex Codes: Complete Hexadecimal, Binary, ASCII, and CSS Color Guide

The Fundamentals of Hexadecimal Notation

Computers do not think in base-10 decimals or English words. They process electrical voltage differentials: binary ones and zeros. Reading raw binary strings like 1101101011111110 quickly overwhelms human comprehension. Base-16 hexadecimal notation (hex) solves this cognitive bottleneck by compressing four binary bits (one nibble) into a single human-readable alphanumeric glyph.

Hexadecimal uses sixteen distinct symbols: digits 0 through 9 represent values zero to nine, and letters A through F represent values ten through fifteen. Because exactly 24 = 16 states exist in four bits, two hexadecimal characters map cleanly to one standard 8-bit byte (28 = 256 states, spanning 0x00 to 0xFF). This direct correspondence makes hex notation foundational across memory addressing, packet sniffing, cryptography, character encoding, and web design color systems.

Table 1: The 4-Bit Nibble Lookup Matrix

Every single byte consists of two 4-bit nibbles: a high nibble and a low nibble. Below is the fundamental translation matrix connecting decimal integers, hexadecimal characters, and their raw 4-bit binary equivalents:

Decimal Value Hexadecimal Character Binary Nibble (4-bit) Bit Weight (8-4-2-1)
0000000 + 0 + 0 + 0
1100010 + 0 + 0 + 1
2200100 + 0 + 2 + 0
3300110 + 0 + 2 + 1
4401000 + 4 + 0 + 0
5501010 + 4 + 0 + 1
6601100 + 4 + 2 + 0
7701110 + 4 + 2 + 1
8810008 + 0 + 0 + 0
9910018 + 0 + 0 + 1
10A10108 + 0 + 2 + 0
11B10118 + 0 + 2 + 1
12C11008 + 4 + 0 + 0
13D11018 + 4 + 0 + 1
14E11108 + 4 + 2 + 0
15F11118 + 4 + 2 + 1

Table 2: Hexadecimal Byte Mapping (0 to 255)

In computer memory and network protocols, data is addressed in bytes. A single byte ranges from decimal 0 (0x00) to 255 (0xFF). Here is how decimal increments translate across common engineering byte thresholds:

Decimal Byte Hex Notation 8-Bit Binary String System Architecture Context
00x0000000000Null byte / String terminator (\0)
160x1000010000First two-digit decimal milestone
320x2000100000ASCII Space character
640x4001000000ASCII '@' symbol / 64-byte memory boundary
1270x7F01111111Maximum positive signed 8-bit integer
1280x8010000000High bit set / Extended ASCII entry
1920xC011000000Common subnet octet (192.168.x.x)
2550xFF11111111Maximum unsigned 8-bit byte / Color channel full saturation

Table 3: Printable ASCII Character to Hex Lookup

The American Standard Code for Information Interchange (ASCII) maps numerical byte values to text glyphs. Programmers debugging hex dumps or binary network sockets rely on this exact byte-to-glyph mapping:

Hex Byte Decimal Glyph Description Hex Byte Decimal Glyph Description
0x2032[SP]Space0x4165AUppercase Latin A
0x2133!Exclamation point0x4266BUppercase Latin B
0x2234"Double quotation0x4367CUppercase Latin C
0x2335#Number sign (Hash)0x4D77MUppercase Latin M
0x2436$Dollar sign0x5A90ZUppercase Latin Z
0x2840(Left parenthesis0x6197aLowercase Latin a
0x2941)Right parenthesis0x6298bLowercase Latin b
0x2A42*Asterisk0x6399cLowercase Latin c
0x2B43+Plus sign0x7A122zLowercase Latin z
0x2D45-Hyphen / Minus0x7B123{Left curly brace
0x2F47/Forward slash0x7D125}Right curly brace
0x30480Digit zero0x7E126~Tilde
0x39579Digit nine0x0A10\nLine Feed
0x3D61=Equals sign0x0D13\rCarriage Return

Bitwise Manipulation: Unpacking Hex Colors in Software

In low-level graphics engines and high-performance game loops, colors are packed into a single 32-bit integer (0xRRGGBBAA or 0x00RRGGBB). Software engineers unpack individual 8-bit color channels using bitwise right shifts (>>) and bitwise AND masks (& 0xFF):

// Unpacking a 24-bit Hex Color Integer in TypeScript
export interface RGBColor {
  r: number;
  g: number;
  b: number;
}

export function unpackHex(hexString: string): RGBColor {
  // Clean leading hash symbol
  const cleanHex = hexString.replace(/^#/, '');
  
  // Parse raw base-16 integer
  const colorInt = parseInt(cleanHex, 16);
  if (isNaN(colorInt)) {
    throw new TypeError(`Invalid hexadecimal color format: ${hexString}`);
  }

  // Bitwise masking and shifting operations
  const r = (colorInt >> 16) & 0xff; // Shift 16 bits, mask low byte
  const g = (colorInt >> 8) & 0xff;  // Shift 8 bits, mask low byte
  const b = colorInt & 0xff;         // Mask low byte directly

  return { r, g, b };
}

// Example: unpackHex('#3b82f6')
// colorInt = 0x3B82F6 (3899638 in decimal)
// r = (0x3B82F6 >> 16) & 0xFF -> 0x3B (59 in decimal)
// g = (0x3B82F6 >> 8) & 0xFF  -> 0x82 (130 in decimal)
// b = 0x3B82F6 & 0xFF         -> 0xF6 (246 in decimal)

Hex in Web Design: From CRT Monitors to OKLCH

For three decades, web styling relied on hexadecimal color notations: #ffffff, #000000, and #3b82f6. Hex notation represented red, green, and blue photon intensities as three pairs of base-16 integers (00 to FF). It mirrored how 1990s cathode-ray tube (CRT) displays mapped electron guns to physical phosphors.

In modern web engineering, hex codes introduce significant architectural constraints. They confine rendering engines to the narrow, legacy sRGB color space, discarding roughly 30% of the richer saturation visible on Display P3 screens, iPhone OLED displays, and MacBook liquid retina panels.

Furthermore, neither hex nor HSL possesses perceptual uniformity. In HSL, pure blue (hsl(240, 100%, 50%)) and pure yellow (hsl(60, 100%, 50%)) share an identical lightness value of 50%. Human vision registers yellow as bright and blue as dark. CSS Color Module Level 4 resolved this by introducing OKLCH.

The Modern Color Space Comparison

Color Format CSS Syntax Example Supported Gamut Perceptually Uniform? Recommended Engineering Use
Hexadecimal #3b82f6 sRGB only No Static legacy fallbacks, build configs
RGB / RGBA rgb(59 130 246 / 0.8) sRGB only No Canvas 2D pixel manipulation
HSL hsl(217 91% 60%) sRGB only No (Distorts luminance) Legacy CSS preprocessors
OKLCH oklch(0.62 0.19 250) Wide Gamut (P3, Rec.2020) Yes (Calibrated to human vision) Design systems, dark modes, token scales

The Architecture of OKLCH

OKLCH models light through mathematical coordinates based directly on human retinal response:

oklch( Lightness  Chroma  Hue ) 
         │          │       │
         │          │       └── Hue Angle (0 to 360 degrees)
         │          │           0 = Red, 90 = Yellow, 140 = Green, 240 = Blue
         │          │
         │          └── Chroma / Saturation (0.0 to ~0.37+)
         │              0 = Pure Grayscale, 0.3+ = Ultra-vivid P3 Display Color
         │
         └── Perceived Lightness (0% = Pure Black, 100% = Pure White)
             Identical number = Identical perceived brightness across ALL hues!

Because lightness is perceptually calibrated, oklch(0.7 0.15 60) (yellow) and oklch(0.7 0.15 250) (blue) have identical perceived luminance. If dark text satisfies contrast ratios on the yellow variant, it is mathematically guaranteed to satisfy contrast ratios on the blue variant.

Automated Palette Generation in TypeScript

Here is an automated palette generator that converts a single brand hue into an accessible, 11-step CSS variable scale:

// src/styles/theme-engine.ts
export interface PaletteStep {
  token: string;
  lightness: number;
  chroma: number;
}

const PALETTE_CURVE: PaletteStep[] = [
  { token: '50',  lightness: 0.97, chroma: 0.02 },
  { token: '100', lightness: 0.93, chroma: 0.04 },
  { token: '200', lightness: 0.86, chroma: 0.08 },
  { token: '300', lightness: 0.77, chroma: 0.12 },
  { token: '400', lightness: 0.68, chroma: 0.16 },
  { token: '500', lightness: 0.58, chroma: 0.20 }, // Primary Brand Shade
  { token: '600', lightness: 0.50, chroma: 0.18 },
  { token: '700', lightness: 0.42, chroma: 0.15 },
  { token: '800', lightness: 0.33, chroma: 0.12 },
  { token: '900', lightness: 0.24, chroma: 0.08 },
  { token: '950', lightness: 0.15, chroma: 0.04 },
];

export function buildOklchScale(hueDegrees: number, prefix = 'brand'): Record {
  const tokens: Record = {};
  for (const step of PALETTE_CURVE) {
    tokens[`--color-${prefix}-${step.token}`] = `oklch(${step.lightness} ${step.chroma} ${hueDegrees})`;
  }
  return tokens;
}

Progressive Enhancement in Modern CSS

Deploy wide-gamut OKLCH colors while providing reliable sRGB hex fallbacks for older browsers:

/* styles/buttons.css */
:root {
  /* sRGB fallback */
  --accent: #2563eb;
}

@supports (color: oklch(0.6 0.2 250)) {
  :root {
    /* Wide-gamut P3 color on modern displays */
    --accent: oklch(0.58 0.22 255);
  }
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-weight: 600;
}

Engineering Conclusion

Hexadecimal notation remains the universal bridge between raw binary machine data and human developers. Whether you are parsing network packets, executing bitwise bit shifts, or defining modern wide-gamut CSS variables, understanding hex fundamentals is an irreplaceable computer science skill.

Found this useful?
View all articles

Keep Reading

Related Articles

Learn with Dropout Developer

Build real software with AI

Step-by-step learning paths, vibe coding tutorials, and certified developer programs designed for the modern engineer.