Skip to main content

Binary data

The data type Binary represents raw binary data as one-dimensional arrays of unsigned bytes. Examples of data that can be represented as byte arrays are raw data from sensors, raster images and compressed data.

Byte arrays can be constructed with the function binary(Charstring hex)->Binary that converts a hexadecimal string hex to a byte array and accessed using the usual array indexing notation b[i].

Example: Assign :b1 to the binary object represented by the hexadecimal string 010245FF.

set :b1 = binary('010245FF')

Get second byte in :b1 as an integer:

:b1[2]

You can convert a vector of integers to a byte array with the function binary(Vector of Integer)->Binary:

set :b2 = binary([0,1,255,48,35])

General queries over binary arrays can be specified.

Example:

select i, :b1[i]
from Integer i
select i,:b1[i]+1
from Integer i
where i>2

You can update byte arrays with the function setf(Binary b, Integer i, Integer v)->Integer:

setf(:b1, 2, 3)
:b1[2]

The hexadecimal string representation of byte arrays and integers can be obtained with the function hex():

hex(:b1);
hex(binary(1234))

Functions

The system functions for handling binary data are documented in Binary data functions.