FormatterHQ

Code to ASCII

Turn a snippet of code or text into character codes, ready to paste as a JavaScript array, Python list or C array with the decoding line included.

Input TEXT
Output TEXT
Ready.

How to use the Code to ASCII

  1. Paste the code or text to convert into the input editor, upload a file, or click Sample to load an example.
  2. Choose a Code format and how to output it with Output as: plain list, JavaScript, Python or C.
  3. Click Convert in the options panel. With Auto update ticked, the result refreshes as you type.
  4. Copy the result from the output panel or download it as a file.

Code to ASCII arrays for your language

Sometimes you need a string as numbers: embedding text in firmware, building test vectors, avoiding quoting problems in generated code, or teaching how strings work. The code to ASCII tool converts every character of your snippet into its character code and wraps the list in ready-to-use syntax.

Example

Input: console.log("hi"); — output as a JavaScript array:

const codes = [99, 111, 110, 115, 111, 108, 101, 46, 108, 111, 103, 40, 34, 104, 105, 34, 41, 59];
const text = String.fromCodePoint(...codes);

The same input as a Python list and as a C array:

codes = [99, 111, 110, 115, 111, 108, 101, 46, 108, 111, 103, 40, 34, 104, 105, 34, 41, 59]
text = "".join(map(chr, codes))
int codes[] = {0x63, 0x6F, 0x6E, 0x73, 0x6F, 0x6C, 0x65, 0x2E, 0x6C, 0x6F, 0x67, 0x28, 0x22, 0x68, 0x69, 0x22, 0x29, 0x3B};

Options

  • Code format — decimal, hex (0x63), octal (0143), binary or HTML references. Hex values are valid in all three languages, but the octal format uses C’s leading-zero style, which Python 3 and strict-mode JavaScript reject — use decimal or hex there.
  • Output as — a plain space-separated list; a JavaScript const array with String.fromCodePoint(...codes) to rebuild the string; a Python list with "".join(map(chr, codes)); or a C int array.

Notes for each language

  • JavaScript. String.fromCodePoint handles any Unicode character, including emoji, because the tool outputs code points rather than UTF-16 units.
  • Python. chr() accepts any code point, so the round trip is exact.
  • C. The array holds code points. For non-ASCII characters you will usually want UTF-8 bytes in a unsigned char array instead — generate them with String to Byte Array.

Common mistakes when rebuilding strings

  • Using String.fromCharCode for emoji. It works in 16-bit units, so a code point such as 128512 (😀) is cut down to the wrong character. String.fromCodePoint, which the generated JavaScript uses, handles it correctly.
  • Treating code points as bytes. In Python, bytes([233]) is the Latin-1 byte for é, not its UTF-8 form. Rebuild text with chr(), or encode it afterwards with .encode("utf-8").
  • Forgetting the terminator in C. The generated int array is data, not a C string. To print it with printf("%s"), copy the values into a char array and add a final 0.
  • Leading zeros in Python. The octal format writes values like 0143, which Python 3 rejects; switch the code format to decimal or hex for Python lists.

A word on obfuscation

Hiding strings as number arrays is sometimes used to make code harder to read. It is trivial to reverse — paste the numbers into ASCII to Text and the text reappears — so it is not a security measure. If you are reviewing unfamiliar code that builds strings from char codes, decoding them is a sensible first step before running it. For per-character details, see Char to ASCII.

The conversion runs locally in your browser.

Frequently asked questions

How do I turn the array back into a string in JavaScript?
Use String.fromCodePoint(...codes), which the JavaScript output already includes. String.fromCharCode works too for characters below U+FFFF.
Does the tool handle emoji?
Yes. It outputs full Unicode code points, so an emoji becomes a single number such as 128512 rather than two surrogate values.
Can I use the octal format in Python?
The octal format uses a C-style leading 0, which Python 3 rejects. Use decimal or hex for Python lists.
Is converting strings to char codes a good way to hide secrets?
No. Anyone can convert the numbers back in seconds. Keep secrets out of source code entirely.

Last updated September 26, 2026

Related tools