Core Function BinaryInsert

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
BinaryInsert( <binary-array>, <binary-array2>, <index> )
+
BinaryInsert( <binary-array>, <binary-array2>, <index>, <overwrite> )
 
</pre>
 
</pre>
  
Line 42: Line 42:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary1 = Pack("z0", "111 333");
+
$binary1 = Pack("A*", "111 333");
$binary2 = Pack("z0", " 222");
+
$binary2 = Pack("A*", " 222");
 
BinaryInsert($binary1, $binary2, 3);
 
BinaryInsert($binary1, $binary2, 3);
 
$k = 0;
 
$k = 0;
Line 51: Line 51:
 
$k++;
 
$k++;
 
}
 
}
println( Unpack("z0", $binary1) ); // Prints: 111 222 333
+
println( Unpack("A*", $binary1, 3) ); // Prints: 111 222 333
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 57: Line 57:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary1 = Pack("z0", "123456");
+
$binary1 = Pack("A*", "123456");
$binary2 = Pack("z0", "abc");
+
$binary2 = Pack("A*", "abc");
 
BinaryInsert($binary1, $binary2, 3, 1);
 
BinaryInsert($binary1, $binary2, 3, 1);
 
$k = 0;
 
$k = 0;
Line 66: Line 66:
 
$k++;
 
$k++;
 
}
 
}
println( Unpack("z0", $binary1) ); // Prints: 123abc
+
println( Unpack("A*", $binary1, 3) ); // Prints: 123abc
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:38, 14 June 2015

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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox