({{, (RefLink[ByteArray, paclet:ref/ByteArray])[{(Subscript[b, 1]),(Subscript[b, 2]),…}] 
constructs a (RefLink[ByteArray, paclet:ref/ByteArray]) object containing the byte values (Subscript[b, i]).}, {, (RefLink[ByteArray, paclet:ref/ByteArray])["string"]
constructs a (RefLink[ByteArray, paclet:ref/ByteArray]) object by extracting byte values from a Base64-encoded string.}})

OpenersNotesSection(Spacer1)Details

(RefLink[ByteArray, paclet:ref/ByteArray]) stores data in a memory-efficient way, with the total number of bytes used being close to the length of the array.

When displayed in (RefLink[InputForm, paclet:ref/InputForm]), a (RefLink[ByteArray, paclet:ref/ByteArray]) object displays as (RefLink[ByteArray, paclet:ref/ByteArray])["string"], where "string" encodes the bytes in Base64 encoding.

In (RefLink[ByteArray, paclet:ref/ByteArray])[{(Subscript[b, 1]),(Subscript[b, 2]),…}], all the byte values (Subscript[b, i]) should be integers between 0 and 255.

(RefLink[Normal, paclet:ref/Normal])[ByteArray[…]] yields the list of byte values in the byte array.

Functions such as (RefLink[Length, paclet:ref/Length]) and (RefLink[Equal, paclet:ref/Equal]) work with (RefLink[ByteArray, paclet:ref/ByteArray]) objects.

Functions such as (RefLink[First, paclet:ref/First]), (RefLink[Last, paclet:ref/Last]), (RefLink[Min, paclet:ref/Min]), and (RefLink[Max, paclet:ref/Max]) yield integer byte values.

(RefLink[Part, paclet:ref/Part]) works on (RefLink[ByteArray, paclet:ref/ByteArray]) objects, yielding an integer byte value when it returns a single element, and a (RefLink[ByteArray, paclet:ref/ByteArray]) object when it returns multiple elements.

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create a (RefLink[ByteArray, paclet:ref/ByteArray]) from a list of byte values:

ByteArray[{1,2,3,4,5,6,5,4,3,2,1}]

Convert back to a list of byte values:

Normal[%]

Create a (RefLink[ByteArray, paclet:ref/ByteArray]) from a Base64-encoded string:

ByteArray["AQIDBAUGBwg="]

Convert to a list of byte values:

Normal[%]

(RefLink[ByteArray, paclet:ref/ByteArray]) uses Base64 in (RefLink[InputForm, paclet:ref/InputForm]):

InputForm[ByteArray[%]]

OpenersExampleSection1(Spacer1)Scope  (6)

Get the length of a (RefLink[ByteArray, paclet:ref/ByteArray]):

Length[ByteArray[Range[32]]]

Extract parts of a (RefLink[ByteArray, paclet:ref/ByteArray]):

b=ByteArray[Range[32]]

First[b]

Last[b]

Extract a sequence of bytes:

b[[5;;10]]

Convert to an ordinary array:

Normal[ByteArray[]]

Reverse a byte array:

Reverse@ByteArray[Range[5]]

Normal[%]

Read in a (StringTypeLink["WXF", paclet:ref/format/WXF]) file as a (RefLink[ByteArray, paclet:ref/ByteArray]):

ReadByteArray["ExampleData/atoms.wxf"]

Read it in 30 bytes at a time:

ReadByteArray["ExampleData/atoms.wxf",30]

ReadByteArray["ExampleData/atoms.wxf",30]

Close the incrementally read file:

Close["ExampleData/atoms.wxf"]

Export an image as a (RefLink[ByteArray, paclet:ref/ByteArray]):

ExportByteArray[,"PNG"]

Interpret a (RefLink[ByteArray, paclet:ref/ByteArray]) as a PNG image:

ImportByteArray[ByteArray[],"PNG"]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

(RefLink[ByteArray, paclet:ref/ByteArray]) uses Base64 encoding of its data in (RefLink[InputForm, paclet:ref/InputForm]):

InputForm[ByteArray[{1,2,3}]]

This string can be generated using (RefLink[BaseEncode, paclet:ref/BaseEncode]):

BaseEncode[ByteArray[{1,2,3}]]

Convert a (RefLink[ByteArray, paclet:ref/ByteArray]) to an ordinary, one-dimensional list using (RefLink[Normal, paclet:ref/Normal]):

ByteArray[{1,2,3}]

Normal[%]

Convert a (RefLink[ByteArray, paclet:ref/ByteArray]) to a string using (RefLink[ByteArrayToString, paclet:ref/ByteArrayToString]):

ByteArrayToString[ByteArray[]]

Convert back to a (RefLink[ByteArray, paclet:ref/ByteArray]) using (RefLink[StringToByteArray, paclet:ref/StringToByteArray]):

StringToByteArray["aáα"]

(RefLink[BinarySerialize, paclet:ref/BinarySerialize]) converts expressions to a sequence of bytes returned as a (RefLink[ByteArray, paclet:ref/ByteArray]):

BinarySerialize[{1,Plot,"hello",Hold[Now]}]

It can be reversed using (RefLink[BinaryDeserialize, paclet:ref/BinaryDeserialize]):

BinaryDeserialize[ByteArray[]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ReadByteArray, paclet:ref/ReadByteArray])  ▪  (RefLink[BinaryWrite, paclet:ref/BinaryWrite])  ▪  (RefLink[BinarySerialize, paclet:ref/BinarySerialize])  ▪  (RefLink[StringToByteArray, paclet:ref/StringToByteArray])  ▪  (RefLink[ByteArrayToString, paclet:ref/ByteArrayToString])  ▪  (RefLink[BaseEncode, paclet:ref/BaseEncode])  ▪  (RefLink[BaseDecode, paclet:ref/BaseDecode])  ▪  (RefLink[Normal, paclet:ref/Normal])  ▪  (RefLink[ByteArrayQ, paclet:ref/ByteArrayQ])  ▪  (RefLink[Encrypt, paclet:ref/Encrypt])  ▪  (RefLink[List, paclet:ref/List])  ▪  (RefLink[NumericArray, paclet:ref/NumericArray])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Binary Data, paclet:guide/BinaryData])}, {▪(RefLinkPlain[Cryptographic Number Theory, paclet:guide/CryptographicNumberTheory])}, {▪(RefLinkPlain[Cryptography, paclet:guide/Cryptography])}})}})