Bytearray Functions(3.1)

The functions described in this section are used to perform operations on variables of the bytearray type.

baAppend

Concatenates two bytearrays and returns the result. None of the input arrays are changed.

bytearray baAppend
(bytearray array1,
bytearray array2 )
ParameterDescription

array1

A bytearray

array2

Another bytearray to append to the end of array1

Returns

The concatenated bytearray

baCreate

Creates a new bytearray of the specified size.

bytearray baCreate( int size )
ParameterDescription

size

Size of the new array in bytes

Returns

A bytearray of the specified size

baCreateFromHexString

Converts a readable hex string into a bytearray.

bytearray baCreateFromHexString( string hexString )
ParameterDescription

hexString

The hex string you want to convert into a bytearray.

Returns

A new bytearray containing the data from the hex string.

Example - Using hex string

If the hex string is "100A" the returned byte array will contain 2 bytes; one with decimal value 16 (which equals hex value 10), and one with decimal value 10 (which equals hex value 0A):

00010000 and 00001010

If the hex string contains an odd number of digits/characters, a "0" will be added at the end of the string, and it will then be handled in the same way as in the example above. For example, if the hex string is "123", a "0" will be added, giving a string containing "1230". The returned bytearray will then contain 2 bytes; one with decimal value 18 (which equals hex value 12) and one with decimal value 48 (which equals hex value 30):

00010010 and 00110000

baGet

Retrieves a byte value from a bytearray. The index must be in the range 0<=index<baSize( array ) or the workflow will abort with a runtime error.

int baGet (bytearray array, int index)
ParameterDescription

array

A bytearray

index

Index of the element to retrieve

Returns

A decimal representation of the indexed byte

Example - Using baGet

Consider a bytearray with the following hex dump "00000000: 484a 4c HJL". Accessing the first element according to the example code, will return "72" - the decimal value of 0x48.

int myVar = baGet( myBA, 0 );

baHexDump

Converts a bytearray into a readable hex dump string, useful for debugging.

string baHexDump( bytearray array )
ParameterDescription

array

A bytearray

Returns

A string containing the hex formatted bytearray

Example - Using baHexDump

Consider a bytearray created with the code in this example.

bytearray myBA = baCreate( 3 ); 
baSet( myBA, 0, 72 );
baSet( myBA, 1, 74 );
baSet( myBA, 2, 76 ); 
string myDump = baHexDump(myBA);


Using the bytearray as input to baHexDump will output a hex dump with the following appearance:

"00000000: 484a 4c HJL"

baInsert

Inserts one bytearray into another bytearray and returns a new bytearray containing the two merged bytearrays.

bytearray baInsert
( bytearray ba1,
int pos,
bytearray ba2 )
ParameterDescription

ba1

The bytearray into which you want to insert bytearray ba2

pos

The position in bytearray ba1 where you want to insert bytearray ba2

ba2

The bytearray you want to insert into bytearray ba1

Returns

A new bytearray containing the data in bytearrays ba1 and ba2 arranged in the order determined by the pos parameter

baReplace

Replaces the data in one bytearray with the data in another bytearray and returns a new bytearray with the replaced data.

bytearray baReplace
( bytearray ba1,
int pos,
bytearray ba2 )
ParameterDescription

ba1

The bytearray in which you want bytes to be replaced

pos

The position in ba1 where you want the replacement to start

ba2

The bytearray containing the bytes you want replace the bytes in ba1 with

Returns

A new bytearray containing the replaced bytes arranged in the order determined by the pos parameter

baSet

Sets the value of a byte in the bytearray. The index must be in the range 0<=index<baSize( array ) or the workflow will abort with a runtime error.

void baSet
( bytearray array,
int index,
int value )
ParameterDescription

array

A bytearray.

index

Index of the byte to set

value

The new value of the byte. The actual value set is ( value & 0xFF )

Returns

Nothing

baSize

Returns the size of an array.

int baSize( bytearray array )
ParameterDescription

array

A bytearray

Returns

The size of the array in bytes