Skip to main content
HexConverter

Hexadecimal in Programming Languages

A definitive guide to hexadecimal syntax across modern software development. Learn literal conventions (0x), byte escapes (\x), Unicode codepoints (\u), URL percent-encoding (%XX), and HTML character entities.

1. Hexadecimal Integer Literals (0x...)

Across virtually all modern languages (C, C++, Rust, Go, Python, JavaScript, Java, C#), hexadecimal integers are written using the 0x or 0X prefix.

// C / C++
uint32_t mask = 0xFF00AA;
// Rust
let color: u32 = 0xDEAD_BEEF;
# Python
buffer_size = 0x1000 # 4096 bytes
// JavaScript / TypeScript
const maxByte = 0xFF; // 255

2. String Byte Escapes (\x) vs. Unicode (\u)

When encoding binary buffers or unprintable control characters inside text strings:

  • Byte Escape (\xHH): Encodes an 8-bit byte. E.g., "\x41\x42" evaluates to "AB".
  • 16-Bit Unicode (\uHHHH): Encodes a Basic Multilingual Plane code point. E.g., "\u00E9" produces "é".
  • Variable Unicode (\u{H...}): Supported in modern JS and Rust to write any Unicode character up to U+10FFFF without surrogate pairs. E.g., "\u{1F600}" produces "😀".

3. Web Standards: URLs, HTML & CSS

URL Percent-Encoding

Encodes non-ASCII or reserved characters: %20 (space), %2F (slash), %3F (question mark).

HTML Hex Entities

Format: &#xHH;. For example, © renders the copyright symbol (©).

CSS Hex Colors

Syntax: #RRGGBB or #RRGGBBAA. For example, #0284C7 defines sky blue.

Need to inspect string bytes in real-time?

Convert UTF-8 text strings to hex with our interactive byte table inspector.

Open Text to Hex Tool

Frequently Asked Questions

Direct answers to technical and practical questions regarding this tool and base-16 conversion.

Why do programming languages use the 0x prefix for hexadecimal numbers?

The "0x" prefix tells lexical analyzers and compilers that the following sequence of characters should be evaluated in base 16 rather than base 10. The leading "0" ensures that the token begins with a digit (distinguishing it from variable names), and the "x" stands for hexadecimal.

What is the difference between \x, \u, and \U in string literals?

In C, Python, and JavaScript, "\x" specifies a single 8-bit byte using two hex digits (e.g. "\x48" for "H"). The "\u" escape specifies a 16-bit Unicode code point with four hex digits (e.g. "\u00E9" for "é"). In Python and C++, "\U" specifies a full 32-bit Unicode code point using eight hex digits (e.g. "\U0001F600" for "😀").

How does URL percent-encoding relate to hexadecimal?

URL percent-encoding represents non-ASCII or reserved characters by replacing them with a percent sign ("%") followed by two hexadecimal digits representing the byte's ASCII or UTF-8 value. For example, a space character (ASCII 32, hex 0x20) becomes "%20".

Can you use underscores in hexadecimal integer literals for readability?

Yes! Modern programming languages—including Python 3.6+, Rust, Go, Java 7+, C++14 (' separator), and JavaScript (ES2021+)—support numerical digit separators. You can write "0xDEAD_BEEF" or "0xFF_FF_FF_FF" to cleanly distinguish byte boundaries without changing the numerical value.

Related Conversion Tools & Resources

Explore companion converters, bitwise arithmetic calculators, and reference charts.

Sources & Technical References

Technical Verification & Editorial Accountability

Written by Sarah Chen (Embedded Systems Engineer) • Verified by Marcus Brody, PE

Reviewed: 2026-10-02MethodologyEditorial PolicyReport Error