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
constarray withString.fromCodePoint(...codes)to rebuild the string; a Python list with"".join(map(chr, codes)); or a Cintarray.
Notes for each language
- JavaScript.
String.fromCodePointhandles 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 chararray instead — generate them with String to Byte Array.
Common mistakes when rebuilding strings
- Using
String.fromCharCodefor 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 withchr(), or encode it afterwards with.encode("utf-8"). - Forgetting the terminator in C. The generated
intarray is data, not a C string. To print it withprintf("%s"), copy the values into achararray and add a final0. - 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.