Core Function BinaryInsert
BinaryInsert( <binary-array>, <binary-array2>, <index>, <overwrite> )
Contents |
Description
Insert a binary variables data into another binary variable at a specific location.
Parameters
binary-array
The binary variable to insert data to.
binary-array2
The binary variable to copy data from.
index
The index position to insert at.
overwrite
Optional; If this is above 0 the data will be inserted and overwrite existing data in the first array also the first array will NOT increase in size even if the second array is larger.
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
This modifies the original binary variable and does not return a copy.
If the "Overwrite" param is not used or is 0 the binary variable binary-array2 will be inserted into binary-array and increase the size of binary-array.
However if "Overwrite" param above 0 the binary variable binary-array2 will be inserted into binary-array and the size of binary-array will not be increased instead binary-array2 data will overwrite data in binary-array at the given location.
Example
$binary1 = Pack("A*", "111 333"); $binary2 = Pack("A*", " 222"); BinaryInsert($binary1, $binary2, 3); $k = 0; Foreach ($binary1 as $i) { println( DecPad($k, 3) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); $k++; } println( Unpack("A*", $binary1, 3) ); // Prints: 111 222 333
This next example uses the "overwrite" param to overwrite data in the first binary array instead of growing it etc
$binary1 = Pack("A*", "123456"); $binary2 = Pack("A*", "abc"); BinaryInsert($binary1, $binary2, 3, 1); $k = 0; Foreach ($binary1 as $i) { println( DecPad($k, 3) . " Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); $k++; } println( Unpack("A*", $binary1, 3) ); // Prints: 123abc