Core Function BinaryResize

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 38: Line 38:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary = Pack("z0", "Hello World!");
+
$binary = Pack("A*", "Hello World!");
 
BinaryResize($binary, 5);
 
BinaryResize($binary, 5);
 
$k = 0;
 
$k = 0;
Line 46: Line 46:
 
$k++;
 
$k++;
 
}
 
}
println( Unpack("z0", $binary) ); // Prints: Hello
+
println( Unpack("A*", $binary, 3) ); // Prints: Hello
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 52: Line 52:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary = Pack("z0", "Hello World!");
+
$binary = Pack("A*", "Hello World!");
 
BinaryResize($binary, 20, Asc("!"));
 
BinaryResize($binary, 20, Asc("!"));
 
$k = 0;
 
$k = 0;
Line 60: Line 60:
 
$k++;
 
$k++;
 
}
 
}
println( Unpack("z0", $binary) ); // Prints: Hello World!!!!!!!!!
+
println( Unpack("A*", $binary, 3) ); // Prints: Hello World!!!!!!!!!
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:38, 14 June 2015

BinaryResize( <binary-array>, <size>, <data> ) 

Contents

Description

Resize a binary variables data array.

Parameters

binary-array

The binary variable to use.

size

The new size for the binary variables data array.

data

Optional; The byte to place into all new slots (Assuming the new array is larger than the old).

Default is 0

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

This modifies the original binary variable and does not return a copy.

Example

Resize a binary to contain just 1 word:

$binary = Pack("A*", "Hello World!");
BinaryResize($binary, 5);
$k = 0;
Foreach ($binary as $i)
{
	println( "($k) Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
	$k++;
}
println( Unpack("A*", $binary, 3) ); // Prints: Hello

Resize a binary and fill in the gaps with ! symbols :

$binary = Pack("A*", "Hello World!");
BinaryResize($binary, 20, Asc("!"));
$k = 0;
Foreach ($binary as $i)
{
	println( "($k) Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) );
	$k++;
}
println( Unpack("A*", $binary, 3) ); // Prints: Hello World!!!!!!!!!
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox