bin2hex encode & decode online
Encode or decode text with bin2hex. No key needed, fully reversible, and nothing leaves your browser.
Every byte becomes two hex digits
Each character is turned into its UTF-8 bytes, and each byte is written as two hex digits. Letters from A to z need one byte, ü two, € three and emoji four. Below each character you see its bytes in binary.
6801101000e6501100101l6c01101100l6c01101100o6f011011115 bytes in, 10 characters out: +100 %
Typing in the tool above fills this in. Nothing leaves your browser.
What is Hex (Base16)?
Hex encoding writes every byte as two hexadecimal digits (00 to ff), so "hi" becomes 6869. The result is exactly twice as long as the input and contains only 0–9 and a–f. It is the usual way to show raw bytes, hashes and keys; PHP calls the functions bin2hex() and hex2bin().
- Hashes and checksums
- Keys, IVs and salts
- Hex dumps and debugging
- Escapes like \x41 in code
- MAC addresses
- Colours in CSS (#ff8800)
Why won't my Hex (Base16) decode?
Paste what you have. The check tells you what is wrong, what kind of data is inside and shows the decoded result, including images and files.
- Paste text above or try an example.
Hex, binary, decimal and escapes
The same input in the forms you meet in practice. Shown for hello; type in the box above or in the tool to use your text.
- Lower casewhat the tool returns
68656c6c6f- Upper casesame bytes
68656C6C6F- Bytes with spaceshex dump style
68 65 6c 6c 6f- Escaped (\x)C, Python, PHP strings
\x68\x65\x6c\x6c\x6f- Array (0x)C, Java, JavaScript
0x68, 0x65, 0x6c, 0x6c, 0x6f- Binary8 bits per byte
01101000 01100101 01101100 01101100 01101111- Decimalbyte values 0–255
104 101 108 108 111
The same result in your code
Every snippet encodes hello to 68656c6c6f exactly like the tool, then decodes it back. They are run and compared with the tool before each release.
echo bin2hex('hello'), "\n"; echo hex2bin('68656c6c6f'), "\n";
print("hello".encode().hex()) print(bytes.fromhex("68656c6c6f").decode())
console.log(Buffer.from("hello").toString("hex")); console.log(Buffer.from("68656c6c6f", "hex").toString());
const bytes = new TextEncoder().encode("hello"); console.log([...bytes].map((b) => b.toString(16).padStart(2, "0")).join("")); const back = Uint8Array.from("68656c6c6f".match(/../g), (h) => parseInt(h, 16)); console.log(new TextDecoder().decode(back));
import java.nio.charset.StandardCharsets; import java.util.HexFormat; public class Enc { public static void main(String[] args) throws Exception { System.out.println(HexFormat.of().formatHex("hello".getBytes(StandardCharsets.UTF_8))); System.out.println(new String(HexFormat.of().parseHex("68656c6c6f"), StandardCharsets.UTF_8)); // Java 17+ } }
package main import ( "encoding/hex" "fmt" ) func main() { fmt.Println(hex.EncodeToString([]byte("hello"))) b, _ := hex.DecodeString("68656c6c6f") fmt.Println(string(b)) }
printf '%s' 'hello' | od -An -tx1 -v | tr -d ' \n' # Back to text: printf '%s' '68656c6c6f' | xxd -r -p
Hex (Base16) examples and test values
What the tool returns for these inputs (UTF-8). Use them to check your own code. ↵ marks a line break.
| Input | Hex (Base16) |
|---|---|
| empty string | empty |
abc | 616263 |
hello world | 68656c6c6f20776f726c64 |
Grüße | 4772c3bcc39f65 |
€ | e282ac |
🙂 | f09f9982 |
Why your Hex (Base16) doesn't match
bin2hex('255') gives 323535: the hex codes of the characters 2, 5 and 5. To write the number 255 in hex (ff) use dechex(255) or (255).toString(16).
Hex shows bytes, so the result depends on the charset: "ü" is c3bc in UTF-8 (this tool), fc in Latin-1 and 00fc in UTF-16.
Every byte needs exactly two hex digits. hex2bin('abc') fails because one digit is missing, often a leading zero (0abc).
68 65 6c, 0x68 0x65 or \x68\x65 are common ways to write hex, but hex2bin() and the tool above only take plain digits. Remove them first; the check panel does it for you.
Hex is not case-sensitive: C3BC and c3bc are the same bytes. Compare in one case.
echo "hello" | base64 encodes six bytes, the text plus a line break, and gives aGVsbG8K. printf '%s' hello | base64 gives aGVsbG8=, the same as the tool.
Questions about Hex (Base16)
What does bin2hex do?
It writes every byte of a string as two hex digits: bin2hex("hello") is 68656c6c6f. hex2bin() turns the digits back into the bytes. The tool above does the same with Encode and Decode.
Why is hex twice as long as the text?
One byte has 256 possible values, one hex digit only 16. So every byte needs two digits, and the output is always exactly twice the number of bytes.
What is the difference between bin2hex and dechex?
bin2hex encodes the characters of a string, dechex converts a number. bin2hex("255") is 323535, dechex(255) is ff.
Is hex upper or lower case?
Both are fine and mean the same bytes. PHP, Python and most tools write lower case; some specifications and Windows tools use upper case.