About Base64 to Hex
Converting Base64 to Hex is useful for:
- Debugging and data inspection
- Cryptographic operations
- Low-level data manipulation
- Hardware and protocol interfacing
How to Convert Base64 to Hex
- 1Paste or type your Base64 string into the input field.
- 2The tool automatically validates the Base64 format.
- 3Choose your preferred hex output format (plain, spaced, prefixed, or array).
- 4Copy the result or download it for further use.
Code Examples
JavaScript
// Convert Base64 string to hex
function base64ToHex(base64String) {
// Decode Base64 to binary string
const binary = atob(base64String);
// Convert binary string to hex
let hex = '';
for (let i = 0; i < binary.length; i++) {
const hexByte = binary.charCodeAt(i).toString(16).padStart(2, '0');
hex += hexByte;
}
return hex;
}
// Example usage
const base64String = 'SGVsbG8gV29ybGQ=';
const hex = base64ToHex(base64String);
console.log(hex); // Output: 48656c6c6f20576f726c64
// With 0x prefix
console.log('0x' + hex); // Output: 0x48656c6c6f20576f726c64Python
import base64
def base64_to_hex(base64_string):
# Decode Base64 to bytes
byte_data = base64.b64decode(base64_string)
# Convert bytes to hex
hex_string = byte_data.hex()
return hex_string
# Example usage
base64_string = 'SGVsbG8gV29ybGQ='
hex_result = base64_to_hex(base64_string)
print(hex_result) # Output: 48656c6c6f20576f726c64
# With 0x prefix
print(f'0x{hex_result}') # Output: 0x48656c6c6f20576f726c64
# With spaces
spaced_hex = ' '.join([hex_result[i:i+2] for i in range(0, len(hex_result), 2)])
print(spaced_hex) # Output: 48 65 6c 6c 6f 20 57 6f 72 6c 64PHP
<?php
function base64ToHex($base64String) {
// Decode Base64 to binary
$binary = base64_decode($base64String);
// Convert binary to hex
$hex = bin2hex($binary);
return $hex;
}
// Example usage
$base64String = 'SGVsbG8gV29ybGQ=';
$hexResult = base64ToHex($base64String);
echo $hexResult; // Output: 48656c6c6f20576f726c64
// With 0x prefix
echo '0x' . $hexResult; // Output: 0x48656c6c6f20576f726c64
// As array
$hexArray = str_split($hexResult, 2);
echo implode(', ', array_map(fn($h) => "0x$h", $hexArray));
// Output: 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64
?>Node.js
// Convert Base64 string to hex
function base64ToHex(base64String, options = {}) {
const { format = 'plain' } = options;
// Create buffer from Base64
const buffer = Buffer.from(base64String, 'base64');
// Convert to hex
let hex = buffer.toString('hex');
// Format output based on options
switch (format) {
case 'spaced':
return hex.match(/.{1,2}/g).join(' ');
case 'prefixed':
return '0x' + hex;
case 'array':
return hex.match(/.{1,2}/g).map(h => `0x${h}`).join(', ');
default:
return hex;
}
}
// Example usage
const base64String = 'SGVsbG8gV29ybGQ=';
console.log(base64ToHex(base64String));
// Output: 48656c6c6f20576f726c64
console.log(base64ToHex(base64String, { format: 'spaced' }));
// Output: 48 65 6c 6c 6f 20 57 6f 72 6c 64
console.log(base64ToHex(base64String, { format: 'prefixed' }));
// Output: 0x48656c6c6f20576f726c64
console.log(base64ToHex(base64String, { format: 'array' }));
// Output: 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64Key Features
- Automatic Base64 validation
- Multiple output formats (plain, spaced, prefixed, array)
- Uppercase/lowercase hex options
- Byte count and size information
- Instant conversion
- Copy to clipboard functionality
- Download converted result
- Client-side processing (secure and private)
Common Use Cases
Debugging
Inspect Base64 encoded data in hexadecimal format for easier debugging and analysis.
Cryptography
Convert Base64 encoded hashes or keys to hex format for cryptographic operations.
Data Inspection
Examine binary data structure and byte values in human-readable hex format.
Protocol Analysis
Decode Base64 data to hex for network protocol analysis and reverse engineering.
Frequently Asked Questions
What are the different hex output formats?
Our tool supports multiple formats: Plain (48656c6c6f), Spaced (48 65 6c 6c 6f), Prefixed with 0x (0x48656c6c6f), and Array format (0x48, 0x65, 0x6c). Choose the format that best suits your needs.
Why would I convert Base64 to hex?
Converting to hex is useful for debugging, examining binary data structure, interfacing with systems that expect hex input, or analyzing cryptographic operations. Hex format is often more readable than Base64 for low-level data inspection.
Can I convert large Base64 strings?
Yes, the tool can handle large Base64 strings, though extremely large files (several megabytes) may slow down the browser. For very large files, consider using command-line tools.
What if my Base64 string is invalid?
The tool will validate your Base64 input and display an error message if the format is invalid. Make sure your Base64 string only contains valid characters (A-Z, a-z, 0-9, +, /, =) and has proper padding.
Is my data secure?
Absolutely. All conversions happen locally in your browser using JavaScript. Your Base64 data is never uploaded to any server, ensuring complete privacy and security.