FormatterHQ

String to Byte Array

Turn text into its UTF-8 byte values as a space-separated list, an array literal, or signed bytes as Java and Kotlin print them.

Loading tool…
Ready.

How to use the String to Byte Array

  1. Type or paste into the Text box, or click Sample. You can also drop a text file on either box, or load one into the Bytes box with its Open file button.
  2. The Bytes box updates live as you type. It works both ways — edit the Bytes side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Byte list in the options bar above the editors; the result refreshes immediately. Decode notation only affects the reverse direction, when you type in the Bytes box.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

String to byte array in UTF-8

Computers store text as bytes. The string to byte array converter encodes your text as UTF-8 and lists the resulting byte values in decimal — the same values you get from "text".getBytes(StandardCharsets.UTF_8) in Java, Encoding.UTF8.GetBytes() in C#, 'text'.encode('utf-8') in Python or new TextEncoder().encode() in JavaScript.

Output formats

Input: Hi café

FormatOutput
Space separated72 105 32 99 97 102 195 169
Array[72, 105, 32, 99, 97, 102, 195, 169]
Signed Java bytes[72, 105, 32, 99, 97, 102, -61, -87]

The “é” at the end is two bytes: 195 and 169 (C3 A9 in hex).

Characters, bytes and string length

CharacterUTF-8 bytesJavaScript .length
a1 (97)1
é2 (195 169)1
€3 (226 130 172)1
🚀4 (240 159 154 128)2

Languages count string length differently — JavaScript and Java count UTF-16 code units, Python counts code points — but storage limits and network protocols count bytes. This tool shows the byte count you actually need.

Why signed bytes?

Java, Kotlin and C# sbyte use signed 8-bit integers ranging from −128 to 127. A byte value above 127 is stored as a negative number: 195 becomes 195 − 256 = −61. When you print a Java byte[] with Arrays.toString() you see these negative values, so the signed format lets you compare your output directly with what the JVM shows. Python, JavaScript Uint8Array, Go and C# byte are unsigned and use 0–255.

Pasting the array into code

Which format to copy depends on the language, because some compilers reject values outside their byte range:

// Java and Kotlin: bytes are signed, so use the signed format
byte[] data = { 72, 105, -61, -87 };      // 195 would not compile

// C#: byte is unsigned (sbyte is the signed type)
byte[] data = { 72, 105, 195, 169 };

# Python
bytes([72, 105, 195, 169]).decode("utf-8")   # 'Hié'

// JavaScript
new TextDecoder().decode(new Uint8Array([72, 105, 195, 169]));

// Go
data := []byte{72, 105, 195, 169}

In Java, writing 195 in a byte[] initializer fails with a "possible lossy conversion from int to byte" error, which is exactly why the signed output exists.

Common uses

  • Writing unit tests that compare byte arrays for an encoder, parser or network protocol.
  • Checking how many bytes a string needs for a database column, message size limit or fixed-length record.
  • Hard-coding a byte array constant, such as a file signature or protocol header.
  • Understanding why a string with emoji or accents is longer in bytes than in characters.

To go back from numbers to text, use Byte to String, which also accepts negative Java bytes. For hexadecimal output, see String to Hex, and for binary digits use Text to Binary. All conversion is local to your browser.

Frequently asked questions

Why are some bytes negative?
In the signed Java format, bytes above 127 are shown as negative numbers (value − 256), matching Java’s signed byte type. The underlying bits are identical.
Which encoding does the tool use?
UTF-8, the default in most modern languages and on the web. Other encodings such as UTF-16 or Latin-1 would give different bytes.
How do I get a byte array in Python?
Use "text".encode("utf-8"), which returns a bytes object. list() on it gives the same numbers as the tool’s array format.
Why does my string have more bytes than characters?
In UTF-8, characters outside ASCII take two to four bytes each. “café” has four characters but five bytes.

Last updated October 3, 2026

Related tools