Bytearray Functions
The functions described in this section are used to perform operations on variables of the bytearray
type.
The following functions for Bytearray described here are:
baAppend
Concatenates two bytearrays and returns the result. None of the input arrays are changed.
bytearray baAppend (bytearray array1, bytearray array2 )
Parameter | Description |
---|---|
| A bytearray |
| Another bytearray to append to the end of |
Returns | The concatenated bytearray |
baCreate
Creates a new bytearray of the specified size.
bytearray baCreate( int size )
Parameter | Description |
---|---|
| 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 )
Parameter | Description |
---|---|
| 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(
or the workflow will abort with a runtime error.array
)
int baGet (bytearray array, int index)
Parameter | Description |
---|---|
| A bytearray |
| 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 )
Parameter | Description |
---|---|
| 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 )
Parameter | Description |
---|---|
| The bytearray into which you want to insert bytearray |
| The position in bytearray |
| The bytearray you want to insert into bytearray |
Returns | A new bytearray containing the data in bytearrays |
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 )
Parameter | Description |
---|---|
| The bytearray in which you want bytes to be replaced |
| The position in |
| The bytearray containing the bytes you want replace the bytes in |
Returns | A new bytearray containing the replaced bytes arranged in the order determined by the |
baSet
Sets the value of a byte in the bytearray. The index must be in the range 0<=index<baSize(
or the workflow will abort with a runtime error.array
)
void baSet ( bytearray array, int index, int value )
Parameter | Description |
---|---|
| A bytearray. |
| Index of the byte to set |
| The new value of the byte. The actual value set is ( |
Returns | Nothing |
baSize
Returns the size of an array.
int baSize( bytearray array )
Parameter | Description |
---|---|
| A bytearray |
Returns | The size of the array in bytes |