Hex Encode & Decode
Free online Hex Encode & Decode tool. 100% local processing — your data never leaves your device.
Result will be displayed here...
Input → Encode
Usage Guide
About Hex (Hexadecimal)
Hex (Hexadecimal) is an encoding method that uses 16 characters (0-9, A-F) to represent binary data. Each hexadecimal character represents 4 binary bits (0-15), so each byte (8 bits) can be represented by 2 hexadecimal characters. Hex-encoded data is 200% the size of the original data, larger than Base64, but more readable and debugging-friendly. Hex is widely used in color codes, MAC addresses, hash values, memory addresses, and other scenarios, making it one of the most commonly used encoding methods for programmers.
Usage Steps
Hex encoding and decoding is very simple:
Encoding Principle
Hex encoding converts binary data to hexadecimal characters through the following process:
0xFF (255) encodes to “FF”, byte 0x41 (65, character 'A') encodes to “41”. String “Hello” encodes to “48656C6C6F”.Hex Format Variants
Hex encoding has several common format variants:
Application Scenarios
Hex is widely used in scenarios requiring readability and debugging-friendliness:
FAQ
Q: What's the difference between Hex and Base64?
A: Hex and Base64 are both text representations of binary data, but have different characteristics. Hex: 1) Uses 16 characters (0-9, A-F). 2) Encoded size is 200% of original data. 3) More readable, suitable for debugging. Base64: 1) Uses 64 characters (A-Z, a-z, 0-9, +, /). 2) Encoded size is approximately 133% of original data. 3) More compact, suitable for transmission. Selection Advice: 1) Need readability and debugging: use Hex. 2) Need compact transmission: use Base64. 3) Encryption algorithm output: typically uses Hex (such as SHA-256).
Q: Why are hash values typically represented in Hex?
A: Hash algorithms (such as SHA-256, MD5) output binary data, typically represented in Hex. Reasons: 1) Readability: Hex is more readable than binary, easy for manual comparison. 2) Fixed Length: SHA-256 outputs 32 bytes, represented as 64 Hex characters with fixed length. 3) Traditional Practice: Encryption and hashing fields traditionally use Hex. 4) Debugging-Friendly: Developers can easily copy, paste, and compare hash values. Example: SHA-256(“hello”) = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824.
Q: What are Hex color codes?
A: Hex color codes represent RGB colors using hexadecimal notation, formatted as #RRGGBB. Format: 1) #RRGGBB: 6-digit hexadecimal, each 2 digits represent a color channel (red, green, blue). 2) #RGB: 3-digit shorthand, each digit repeated once (e.g., #F00 = #FF0000). Examples: 1) #FF0000: Pure red (R=255, G=0, B=0). 2) #00FF00: Pure green (R=0, G=255, B=0). 3) #0000FF: Pure blue (R=0, G=0, B=255). 4) #FFFFFF: White. 5) #000000: Black. Conversion: Hex colors can be converted to RGB (e.g., rgb(255, 87, 51)) or HSL (e.g., hsl(14, 100%, 60%)).
Q: Why are MAC addresses represented in Hex?
A: MAC addresses (Media Access Control Address) are physical addresses of network devices, represented in Hex. Format: 6 bytes (48 bits), typically separated by colons or hyphens, such as 00:1A:2B:3C:4D:5E or 00-1A-2B-3C-4D-5E. Reasons: 1) Compact: 6 bytes represented by 12 hexadecimal characters, more compact than binary (48 bits) or decimal (14-digit number). 2) Readable: Hex is more readable than binary, easy for manual identification and input. 3) Standard: IEEE 802 standard specifies using Hex to represent MAC addresses. Example: 00:1A:2B:3C:4D:5E represents MAC address 0x001A2B3C4D5E.
Q: How to use Hex in JavaScript?
A: JavaScript provides multiple methods for handling Hex encoding. String to Hex:const str = 'Hello';
const hex = Array.from(str).map(c => c.charCodeAt(0).toString(16).padStart(2, '0')).join('');
// Result: '48656c6c6f'
Hex to String:const hex = '48656c6c6f';
const str = hex.match(/.{1,2}/g).map(byte => String.fromCharCode(parseInt(byte, 16))).join('');
// Result: 'Hello'
Number to Hex: const hex = (255).toString(16); // 'ff'
Hex to Number: const num = parseInt('ff', 16); // 255
Q: What is a Hex editor?
A: A Hex editor is a tool for viewing and editing binary files, displaying file contents in hexadecimal format. Features: 1) View Binary Files: Display each byte of a file in Hex format. 2) Edit Binary Files: Directly modify byte values in files. 3) Search and Replace: Search for specific byte sequences in binary files. 4) File Analysis: Analyze file structure, find file headers, identify file types. Use Cases: 1) Reverse engineering: Analyze executables, firmware. 2) Data recovery: Repair corrupted files. 3) Game modification: Modify game saves, configurations. 4) Security research: Analyze malware. Common Tools: HxD (Windows), Hex Fiend (macOS), xxd (Linux command line).
Use Cases
Recommended: CSS Color Codes
Hex color codes are the most commonly used color representation in CSS, formatted as #RRGGBB. Each 2 digits of hexadecimal represent a color channel (red, green, blue), with values ranging from 00-FF (0-255). Hex color codes are concise, readable, and the standard for web development. Modern CSS also supports 8-digit Hex colors (#RRGGBBAA), with the last 2 digits representing transparency (Alpha channel).
- ✅ Standard 6-digit Hex (#FF5733)
- ✅ 3-digit shorthand (#F00 = #FF0000)
- ✅ 8-digit Hex with transparency (#FF573380)
- 💡 Use color picker tools to generate Hex colors
- 💡 Consider using CSS variables to manage colors
Recommended: Hash Value Representation
Cryptographic hash algorithms (such as SHA-256, MD5) typically output in Hex format. Hex-formatted hash values are easy to read, copy, paste, and compare, making them the standard format for file integrity verification, digital signatures, password storage, and other scenarios. For example, Git uses SHA-1 hash values (40-digit Hex) to identify commits, and blockchains use SHA-256 hash values (64-digit Hex) to identify blocks.
- ✅ File integrity verification (SHA-256)
- ✅ Git commit IDs (SHA-1)
- ✅ Blockchain block hashes (SHA-256)
- ✅ Password hashes (bcrypt, Argon2)
- 💡 Use lowercase Hex for consistency
Recommended: MAC Addresses and Network Identifiers
MAC addresses (physical addresses) use 6 bytes (48 bits) of Hex representation, formatted as XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX. MAC addresses uniquely identify network devices, with the first 3 bytes being the vendor identifier (OUI) and the last 3 bytes being the device serial number. Similarly, IPv6 addresses also use Hex representation (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).
- ✅ MAC addresses (00:1A:2B:3C:4D:5E)
- ✅ IPv6 addresses (2001:db8::1)
- ✅ Network device identifiers
- 💡 Use colon separators for better readability
Recommended: UUIDs and Unique Identifiers
UUIDs (Universally Unique Identifiers) use Hex representation, formatted as xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (32 Hex digits + 4 hyphens). UUIDs generate globally unique identifiers, widely used in database primary keys, distributed systems, file systems, and other scenarios. UUIDs have multiple versions (v1-v5), with v4 (randomly generated) being the most common.
- ✅ Database primary keys
- ✅ Distributed system IDs
- ✅ File system identifiers
- ✅ API request IDs
- 💡 Use UUID v4 (random) or v7 (timestamp)
Recommended: Binary File Analysis
Using Hex editors to view and edit binary files is a common method in reverse engineering, data recovery, and security research. Hex editors display each byte of a file in hexadecimal format, making it easy to analyze file structure, find file headers, and identify file types. For example, PNG files start with 89 50 4E 47 (.PNG), and JPEG files start with FF D8 FF.
- ✅ Reverse engineering (analyzing executables)
- ✅ Data recovery (repairing corrupted files)
- ✅ File format analysis
- ✅ Security research (analyzing malware)
- 💡 Use professional Hex editors (HxD, Hex Fiend)
Recommended: Memory Addresses and Debugging
During program debugging, memory addresses are typically represented in Hex (e.g., 0x7FFF5FBFF000). Hex-formatted memory addresses are easy to read and compare, and are the standard format for debuggers (such as GDB, LLDB, WinDbg). Developers can use Hex addresses to view memory contents, set breakpoints, and analyze program behavior.
- ✅ Debuggers (GDB, LLDB, WinDbg)
- ✅ Memory dump analysis
- ✅ Pointer and address calculations
- ✅ Assembly language development
- 💡 Use 0x prefix to indicate hexadecimal numbers
Best Practice Recommendations
- Hex-encoded data is 200% the size of original data, not suitable for large file transmission; use Base64 or binary transmission instead.
- Hash values typically use lowercase Hex for consistency (e.g., Git, blockchain).
- CSS color codes more commonly use uppercase Hex (#FF5733), but lowercase (#ff5733) is also acceptable.
- MAC addresses more commonly use colon separators (00:1A:2B:3C:4D:5E) than hyphens (00-1A-2B-3C-4D-5E).
- In JavaScript, use toString(16) to convert numbers to Hex, and parseInt(hex, 16) to convert Hex to numbers.
- Hex editors are powerful tools for analyzing binary files, but require understanding of file formats and byte order (big-endian/little-endian).