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é
| Format | Output |
|---|---|
| Space separated | 72 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
| Character | UTF-8 bytes | JavaScript .length |
|---|---|---|
| a | 1 (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.