Skip to main content
Byte Array Tools

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.

The 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

  1. Type or paste the text.
  2. Choose the text encoding - UTF-8 unless the receiving system says otherwise.
  3. Choose how to write the result: the language, decimal, hex or binary values, values per line and the variable name.
  4. 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

In UTF-8, only ASCII characters take one byte. Accented letters take two bytes, most other scripts (including Hindi and Chinese) take three, and emoji take four. A 10-character string can therefore be 10 to 40 bytes.

Use UTF-8 unless the system you are talking to says otherwise. It is the default for the web, JSON, most databases and modern programming languages. Choose UTF-16 LE for Windows APIs and .NET strings, and Latin-1 only for old systems that require it.

Java bytes are signed, from -128 to 127, so a hex literal such as 0xF0 (240) does not fit without a cast. The tool adds (byte) to every value above 0x7F. In decimal output it writes the negative value instead, for example -16 for 0xF0.

No. The array contains exactly the bytes of the text. If your C code expects a null-terminated string, add 0x00 at the end of the array yourself, or declare it as a string literal instead.
Share this tool: