Core Function BinaryMid
BinaryMid( <binary-array>, <start>, <length> )
Contents |
Description
Create a binary variable by extracting a number of bytes from another binary variable.
Parameters
binary-array
The binary variable to use.
start
Position to start from.
If the start is a negative value the position will work backwards from the length of the binary.
length
Optional; How many bytes to copy.
Default is all remaining bytes;
If length is given and is negative, then that many bytes will be omitted from the end of binary (after the start position has been calculated when a start is negative).
If start denotes the position of this truncation or beyond, empty binary variable will be returned.
Return Value
Success: Returns a new binary variable.
Failure: Returns empty binary variable.
Remarks
This does not modify the original.
Example
Copy from "brown" to end of the data:
$binary = Pack("A*", "The quick brown FoX"); $binary2 = BinaryMid($binary, 10); println("b1: " . Unpack("A*", $binary, 3)); println("b2: " . Unpack("A*", $binary2, 3));
Copy just the "FoX" part example:
$binary = Pack("A*", "The quick brown FoX"); $binary2 = BinaryMid($binary, 16, 3); println("b1: " . Unpack("A*", $binary, 3)); println("b2: " . Unpack("A*", $binary2, 3));