String to Byte Array Converter
Convert text to a byte array in UTF-8, UTF-16, Latin-1 or ASCII, as decimal, hex or binary values or ready-to-paste code for Java, C, Python, JavaScript and more.
Type or paste text to see exactly which bytes it becomes in the encoding you choose - as a plain list or as an array declaration for your language.
Converted in your browser - the text is never sent to a server.
More Byte Array Tools
View all 17The same text gives different bytes in different encodings - pick the one the receiving system expects, usually UTF-8.
What Is the String to Byte Array Converter?
Computers store text as bytes, and the bytes depend on the encoding. This tool shows the exact bytes a string becomes in UTF-8, UTF-16 (little or big-endian), ISO-8859-1 (Latin-1) or ASCII, and writes them as a plain list or as an array declaration for Java, Kotlin, C, C#, Python, JavaScript, Go, Rust, PHP or JSON.
When to Use It
- Checking what
"text".getBytes(StandardCharsets.UTF_8)or"text".encode()will return before you write the code. - Building a test fixture or a hard-coded key, header or protocol message.
- Finding out why a string is longer in bytes than in characters - for example when a database column or an API limit is measured in bytes.
How to Use It
- Type or paste the text.
- Choose the text encoding - UTF-8 unless the receiving system says otherwise.
- Choose how to write the result: the language, decimal, hex or binary values, values per line and the variable name.
- Copy the output. It updates as you type.
Example
The text Namaste 🙏 Byteary is 17 characters but 20 bytes in UTF-8, because the folded-hands emoji takes four bytes. As a Java array in hex it starts byte[] data = { 0x4E, 0x61, 0x6D, 0x61, 0x73, 0x74, 0x65, 0x20, (byte) 0xF0, (byte) 0x9F, (byte) 0x99, (byte) 0x8F, .... The (byte) casts are there because Java bytes are signed and cannot hold 0xF0 without one.
Understanding the Output
In UTF-8, English letters, digits and common punctuation are one byte each; accented Latin letters are two; most other scripts, including Hindi and Chinese, are three; emoji are four. UTF-16 uses two bytes for most characters and four for emoji. Latin-1 and ASCII use one byte per character but cannot represent anything outside their small character sets - the tool tells you which character failed instead of silently replacing it.
Limitations
The tool does not add a byte order mark (BOM) or a terminating zero byte - add 0x00 yourself if your C code expects a null-terminated string. Legacy code pages such as Windows-1252 or Shift_JIS are not offered. To go the other way, use the Byte Array to String Converter; to see the bytes of each character in detail, use the UTF-8 Encoder / Decoder.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.