Text to Hex Calculator - Encode Text to Hex Bytes
Use this text to hex calculator to encode ASCII text into a 2-digit hex byte string, pick a separator and case, and see byte and character counts.
Text to Hex Calculator
Results
What Is the Text to Hex Calculator?
A text to hex calculator turns every character of a text string into its 2-digit hexadecimal byte, so the same word reads as ASCII on the screen and as a hex byte string in source code, log lines, packet captures, and database dumps. The calculator handles any 7-bit ASCII character and reports bytes that fall outside that range so the user can swap to a UTF-8 tool for accented letters, CJK characters, or emoji.
Use this calculator when the destination of the text is something other than a human reader. Print logs, hard-coded byte arrays, low-level protocol headers, color codes, and short identifiers all want the text rendered as hex bytes, and typing the encoding by hand invites off-by-one errors. The calculator gives a quick, reproducible byte string for the same characters every time the form is reloaded, and the byte, character, and hex length counters give a fast cross-check against a documented byte boundary.
- • Building a hex string for a log line: Type the message, pick 0x prefix or contiguous, and copy the byte string into the source code.
- • Encoding a fixed string for a database column or header: Encode a short identifier or magic number once and reuse the same bytes across tests and seed data.
- • Round-tripping a string through the hex to text decoder: Encode a known string, paste the bytes into the matching tool, and confirm the round trip.
- • Reading hex dumps and packet captures: Match a printed log line to its source characters by encoding the same phrase in a known separator and comparing byte-for-byte.
The calculator covers the same 0x00-0x7F range that the existing Hex to Text Converter reads back, so any string that encodes cleanly here will decode cleanly there.
How the Text to Hex Calculator Works
The encoder reads each character of the input string, looks up its UTF-16 code unit, writes the value in base 16, and pads the result to 2 hex digits. The bytes are then joined with the chosen separator and case policy.
- textInput: The text string to encode. Empty string returns an empty hex output with all counts at zero.
- byteFormat: How the bytes are joined: contiguous, space-separated, colon-separated, or 0x-prefixed.
- letterCase: Either keeps the natural case, lower forces a-f, upper forces A-F.
- hexOutput: The encoded hex string in the chosen format.
- byteCount: Number of 2-digit hex bytes in the encoded output.
- characterCount: Number of characters in the text input.
- hexLength: Number of hex digits in the contiguous form (2 times the byte count).
Bytes above 0x7F are skipped and listed in the warning so the user can see exactly which character did not encode; multi-byte UTF-8 characters such as accented letters and emoji have a code unit above 0x7F.
Encode 'Hi!' to the space-separated hex bytes '48 69 21'
Text Input = 'Hi!', Byte Format = Space-separated, Output Case = Either
1. H: 72 -> '48'. 2. i: 105 -> '69'. 3. !: 33 -> '21'. 4. Join with a space: '48 69 21'.
Hex output: 48 69 21. Byte count: 3 bytes. Character count: 3 characters. Hex length: 6 hex digits.
Three printable ASCII characters, three 2-digit hex bytes. The same string decodes back to 'Hi!' with the matching hex to text converter on the same page.
Encode 'OK' to the upper-case 0x-prefixed bytes '0x4F 0x4B'
Text Input = 'OK', Byte Format = 0x prefix, Output Case = Upper
1. O: 79 -> '4f'. 2. K: 75 -> '4b'. 3. Apply Upper case: '4F', '4B'. 4. Prepend 0x and join with spaces: '0x4F 0x4B'.
Hex output: 0x4F 0x4B. Byte count: 2 bytes. Character count: 2 characters. Hex length: 4 hex digits.
This is the format a C or Rust byte array literal expects: two quoted, space-separated byte values that drop straight into a source file.
According to ECMA International ECMA-6, the printable ASCII letters occupy the 7-bit codes 65-90 for uppercase and 97-122 for lowercase, which is why 'A' encodes to 0x41 and 'a' encodes to 0x61. The MDN String.fromCharCode reference documents that charCodeAt returns the UTF-16 code unit and fromCharCode builds a string from those code units, the same byte-or-2-byte value the calculator encodes to hex.
Key Concepts Explained
Four small ideas explain every result the text to hex calculator shows.
2-Digit Hex Byte
One printable ASCII character is exactly one 8-bit byte, written as 2 hex digits. The values 0x41, 0x61, and 0x30 encode the characters A, a, and 0 respectively.
Base-16 From CharCodeAt
charCodeAt(0) returns the UTF-16 code unit of the character, and toString(16) writes that value in base 16. padStart(2, '0') keeps every byte exactly 2 hex digits.
0x Prefix and Separator
A leading 0x on every byte is the byte-literal marker used by C, C++, Rust, Go, and Python; a space or colon between bytes is the format used in log lines and Wireshark exports.
7-Bit ASCII Range
The standard text to hex encoder covers codes 0x00-0x7F, the canonical US-ASCII frame. Bytes above 0x7F are skipped and listed in the warning.
These four ideas line up with what the calculator does: read one character, write its code point in base 16, pad to 2 hex digits, and warn on any byte that does not fit. The ASCII converter reads the matching numeric value for the same character on the same screen, which is useful when the same byte also needs a decimal, binary, or octal code in a spec or table.
How to Use This Calculator
Five short steps cover the common workflow without any setup.
- 1 Type or paste the text: Type the source string in the Text Input box. Letters, digits, punctuation, and whitespace are encoded exactly as they appear; empty input returns an empty hex output.
- 2 Pick a byte format: Use Space-separated for log lines, Colon-separated for readability, 0x prefix for source code literals, and Contiguous for hash digests and short identifiers.
- 3 Pick an output letter case: Use Either to keep the natural case. Use Lower to force a-f and Upper to force A-F on every byte.
- 4 Read the hex output and counts: Hex Output shows the encoded string, Byte Count the number of 2-digit bytes, Character Count the input length, and Hex Length the number of hex digits in the contiguous form.
- 5 Copy the result or fix the warning: If the warning row reports a skipped character, swap to a UTF-8 encoder for that character or remove it from the input before retrying.
Type Hi! in the Text Input box with Byte Format at Space-separated and Output Case at Either. The Hex Output row reads 48 69 21 and the counts read 3, 3, 6. The same source string also encodes into 0/1 bytes through the matching binary to text converter when the destination needs a bit-level string instead of hex bytes.
Benefits of Using This Calculator
A purpose-built text to hex calculator keeps the byte encoding, the case policy, and the separator format in one place.
- • 4 separator formats in one tool: Contiguous, space, colon, and 0x-prefixed bytes share the same selector, covering hash digests, log lines, packet captures, and source code literals.
- • Strict 7-bit ASCII validation: Any character outside the 0x00-0x7F range is skipped and listed in the warning with its code point, so the encoded string never silently drops bytes.
- • Visible byte, character, and hex counts: The counts appear next to the encoded string for a one-step cross-check against a documented byte boundary or header length.
- • Case policy on the output: Either, Lower, and Upper case modes handle natural-case logs, forced-lowercase digests, and forced-uppercase headers with the same selector.
- • Runs entirely in the browser: charCodeAt(0) and toString(16) run on the typed string, so the input never leaves the page and the encoded output updates as soon as a character is typed or removed.
When the encoded string is the start of a base64 message, the matching base64 encoder decoder turns the same byte string into a different alphabet without retyping the source.
Factors That Affect Your Results
Three variables determine what the encoded string looks like, and three limitations tell you when to reach for a different tool.
Input Character Set
The encoder covers the 0x00-0x7F range, so printable ASCII letters, digits, punctuation, and standard control codes all encode to a 2-digit byte. Accented letters, CJK characters, and emoji fall outside the range and are skipped with a warning.
Byte Format Selector
Contiguous, space-separated, colon-separated, and 0x-prefixed bytes are all valid hex strings. The selector only changes how the bytes are joined, not the byte values.
Output Letter Case
The natural output of toString(16) is lowercase a-f. The case selector forces lowercase or uppercase on every byte.
- • The encoder is 7-bit ASCII only. It does not handle Unicode code points above 0x7F, multi-byte UTF-8 sequences, or emoji. For full Unicode support, swap to a UTF-8 encoder.
- • Bytes above 0x7F are skipped and listed in the warning, but the rest of the input is still encoded.
- • The encoder does not reverse the separator format. A 0x-prefixed output is not recoverable as a contiguous run, so copy the encoded string in the format the destination expects.
According to IETF RFC 4648, base16 (hex) encoding uses the alphabet 0-9 and A-F (case-insensitive), which is why the same byte can be written as 48, 4A, 4a, or 4A and still decode to the same character.
When the encoded string is the payload of a fixed-size message header, the data storage converter turns the byte count into KB, MB, and GB so the storage cost of the encoded string is easy to estimate next to the rest of the file.
Frequently Asked Questions
Q: How do you convert text to hex?
A: Type the text in the Text Input box, pick a byte format (contiguous, space, colon, or 0x prefix) and an output letter case, and read the hex output. The encoder reads each character with charCodeAt(0), writes the value in base 16 with toString(16), pads the result to 2 hex digits with padStart(2, '0'), and joins the bytes with the chosen separator.
Q: What does the text to hex calculator do?
A: It turns every character of a text string into its 2-digit hex byte and surfaces any character that does not fit the 7-bit ASCII range. The same calculator handles contiguous runs, space-separated bytes, colon-separated bytes, and bytes prefixed with 0x so the output stays consistent no matter how the destination expects the bytes.
Q: Does the converter add a 0x prefix or space between bytes?
A: Pick Space-separated for 48 69 21, Colon-separated for 48:69:21, 0x prefix for 0x48 0x69 0x21, or Contiguous for 486921. The selector changes only the separator, not the byte values themselves.
Q: Why does the hex output look longer than the input?
A: Every ASCII character is one byte, and every byte is 2 hex digits, so the hex string is at least 2 times the input length. The 5-letter word Hello encodes to 10 hex digits in contiguous form and 14 characters in 0x-prefixed form.
Q: Can the converter handle Unicode characters and emoji?
A: The standard text to hex encoder covers 0x00-0x7F, the canonical US-ASCII range. Unicode characters and emoji fall outside that range and are skipped with a warning that names the skipped character and its code point, so swap to a UTF-8 encoder for full Unicode support.
Q: Is text to hex the same as ASCII to hex?
A: Yes, for the 0x00-0x7F range. Text to hex and ASCII to hex describe the same encoding for printable US-ASCII: one character in, one 2-digit hex byte out. The names diverge only when the input goes past 0x7F.