How to convert a byte array to Base64
- Paste the array into the input. The whole declaration is fine: type names, variable names, brackets and semicolons are skipped.
- The Base64 appears in the output. Padding (=) and Line wrap under the output control the format.
- Copy output, or switch the To menu to another format such as Hex or Base64URL.
- To turn Base64 back into a declaration for a chosen language, use Base64 to Byte Array.
What you can paste
Every line below gives SGkh, the Base64 for the three bytes H, i, !:
| Language | Input |
|---|---|
| C, C++ | unsigned char d[] = {0x48, 0x69, 0x21}; |
| JavaScript | new Uint8Array([72, 105, 33]), Uint8Array.from([72, 105, 33]), Buffer.from([72, 105, 33]) |
| Python | b'Hi!', b'\x48\x69\x21', bytes([72, 105, 33]), bytearray(b'Hi!') |
| Java | new byte[]{72, 105, 33}, (byte) 0x48 casts |
| Go | []byte{0x48, 0x69, 0x21} |
| C# | new byte[] { 0x48, 0x69, 0x21 } |
| Rust | [0x48u8, 0x69, 0x21], vec![72u8, 105, 33] |
| Bare list | 72, 105, 33 or 72 105 33 |
Values can be decimal, hex with 0x, binary with 0b, octal with 0o, or ASCII character literals such as 'H'. Type suffixes like u8, U and L are ignored. Python literals are read with their full escape rules, including \n, \t and octal escapes, and several b'...' pieces in a row, as in a multi-line literal inside parentheses, are joined.
Signed bytes and value ranges
Java has no unsigned byte, so arrays printed from Java or Kotlin contain negative numbers. The converter reads −128 to −1 as the bytes 0x80 to 0xff:
| Input | Bytes | Base64 |
|---|---|---|
{72, 105, -1} | 48 69 ff | SGn/ |
new byte[]{72, 105, (byte) 0xff, -1} | 48 69 ff ff | SGn//w== |
[-34, -83, -66, -17] | de ad be ef | 3q2+7w== |
Anything above 255 or below −128 stops the conversion with the value and its position. Numbers with a leading zero, such as 072, are read as decimal 72, not as C octal 58, which matches what most people mean when they paste a list of byte values.
Formats this page does not read
- Node’s
<Buffer 48 69 21>console output. Those values are hex without0x, and the converter would read them as decimal. Copy the part betweenBufferand>into Hex to Base64. - Quoted C strings such as
"Hi!". Use Text to Base64 for text, or write the bytes as an array. - JSON objects such as
{"type":"Buffer","data":[72,105,33]}. Paste only the[72,105,33]part, here or in Decimal to Base64.
Byte array to Base64 in code
String b64 = java.util.Base64.getEncoder().encodeToString(new byte[] {72, 105, 33}); // "SGkh"
string b64 = Convert.ToBase64String(new byte[] { 0x48, 0x69, 0x21 }); // "SGkh"
import base64
base64.b64encode(bytes([72, 105, 33])).decode() # 'SGkh'
btoa(String.fromCharCode(...new Uint8Array([72, 105, 33]))); // 'SGkh'
The spread passes every byte as a separate argument, so it fails on large arrays: in Node 24 it throws Maximum call stack size exceeded somewhere between 125,000 and 200,000 elements, and the limit differs between engines. For big data, Buffer.from(arr).toString("base64") in Node or arr.toBase64() in current browsers avoids that; see Uint8Array.toBase64. More on each language: Java, C#, Python, JavaScript.
FAQ
How do I convert a byte[] to Base64 in Java?
java.util.Base64.getEncoder().encodeToString(bytes). To check a hard-coded array, paste the whole new byte[] { ... } declaration here, casts and negative values included.
Can I paste a Python bytes literal?
Yes. b'Hi!', b'\x48\x69\x21', octal escapes such as \041, bytes([72, 105, 33]) and several literals split over lines all work.
Why do I get "does not fit in a byte"?
A value is above 255 or below −128. Often the array is really of 16- or 32-bit integers, such as short[] or int[], which need to be split into bytes in a chosen byte order first.
Are numbers without 0x read as hex?
No. A bare 48 is decimal 48. Hex values need the 0x prefix, or paste them into Hex to Base64 instead, which reads unprefixed hex.