Core Function BinaryUnshift

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 30: Line 30:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary = Pack("z0", "One");
+
$binary = Pack("A*", "One");
 
BinaryUnshift($binary, Asc(" "));
 
BinaryUnshift($binary, Asc(" "));
 
BinaryUnshift($binary, Asc("o"));
 
BinaryUnshift($binary, Asc("o"));
 
BinaryUnshift($binary, Asc("w"));
 
BinaryUnshift($binary, Asc("w"));
 
BinaryUnshift($binary, Asc("T"));
 
BinaryUnshift($binary, Asc("T"));
println( "'" . Unpack("z0", $binary) . "'" ); // Prints: Two One
+
println( "'" . Unpack("A*", $binary, 3) . "'" ); // Prints: Two One
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 16:26, 27 September 2013

BinaryUnshift( <binary-array>, <byte> ) 

Contents

Description

Add a byte to the beginning of a binary variable.

Parameters

binary-array

The binary variable to use.

byte

The byte to add to the beginning of the binary data.

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

Binary data is not really meant to be resized like crazy, so if you have a LOT of data, it is best to avoid using this too often.

Example

$binary = Pack("A*", "One");
BinaryUnshift($binary, Asc(" "));
BinaryUnshift($binary, Asc("o"));
BinaryUnshift($binary, Asc("w"));
BinaryUnshift($binary, Asc("T"));
println( "'" . Unpack("A*", $binary, 3) . "'" ); // Prints: Two One
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox