Search

1. Preface
2. The Transformation Language
3. Constants
4. Operators
5. Variables
6. Dates
7. Functions
8. Creating Custom Functions
9. Custom Function API Reference # BINARY_SECTION

Returns a portion of a binary value.
To use the
BINARY_SECTION
function, set the environment variable
INFA_ENABLE_BINARY_FUNCTIONS
to True or Yes.

## Syntax

`BINARY_SECTION( binary, start [,length] )`
The following table describes the argument for this command:
Argument
Required/
Optional
Description
binary
Required
You can enter a binary value or any transformation expression that returns a binary datatype.
start
Required
You can enter an integer or any transformation expression that returns an integer.
The position in the binary where you want to start counting. If the start position is a positive number,
BINARY_SECTION
locates the start position by counting from the beginning of the input binary.
If the start position is a negative number,
BINARY_SECTION
locates the start position by counting from the end of the input binary.
If the start position is 0,
BINARY_SECTION
searches from the first byte in the input binary.
length
Optional
You can enter an integer greater than 0 or any transformation expression that returns a positive integer.
The number of bytes you want
BINARY_SECTION
to return. If you omit the length argument,
BINARY_SECTION
returns all of the bytes from the start position to the end of the input binary. If you pass a negative integer or 0, the function returns an error.

## Return Value

Binary.
NULL if the input is a null value.

## Example

The following expressions return the first three bytes of a binary value.
`BINARY_SECTION( SYSID, 0, 3 )`
`SYSID (Shown in Hex)`
`RETURN VALUE (Shown in Hex)`
`0x00010203`
`0x000102`
`0x0405060708`
`0x040506`
`NULL`
`NULL`
The following expressions return bytes 4 through 8 of a binary value.
`BINARY_SECTION( SYSID, 4, 5 )`
`SYSID (Shown in Hex)`
`RETURN VALUE (Shown in Hex)`
`0x000102030405060708`
`0x0304050607`
`0x0405060708090A0B`
`0x0708090A0B`
`NULL`
`NULL`
You can also pass a negative start value. The expression still reads the source binary from left to right when returning the result of the
length
argument:
`BINARY_SECTION( SYSID, -6, 5 )`
`SYSID (Shown in Hex)`
`RETURN VALUE (Shown in Hex)`
`0x000102030405060708`
`0x0304050607`
`0x0405060708090A0B`
`0x060708090A`
`NULL`
`NULL`
When the
length
argument is longer than the input value,
BINARY_SECTION
returns all the bytes from the start position to the end of the input value. Consider the following example:
`BINARY_SECTION( SYSID, 2, 8 )`
where SYSID is the binary equivalent of 0x000102030405.
The return value is the binary equivalent of 0x0102030405. Compare this result to the following example:
`BINARY_SECTION ( SYSID, -2, 8)`
where SYSID is the binary equivalent of 0x000102030405.
The return value is the binary equivalent of 0x0405.
Actions
Resources