"Sputnik" help  
Sputnik Help
BinarySize(<binary>, <size>, [<fromLeft>])

Description

Resizes a binary string to the specified size. If the new size is larger than the current size, the binary string will be grown by adding filler bytes. If the new size is smaller, the binary string will be shrunk by removing bytes from either end.

Parameters

<binary> The binary string to be resized.
<size> The new absolute size of the binary string.
<fromLeft> Optional boolean value indicating whether the resizing should occur from the left side. If set to true, the binary string will be resized from the beginning. If not provided or set to false, the resizing will occur from the end.

Return Value

Success: Returns the resulting binary string after resizing.
Failure: Returns current size (means no change).

Remarks

The BinarySize function allows you to change the size of a binary string to a specified absolute size. If the new size is larger than the current size, the binary string will be grown by adding filler bytes. If the new size is smaller, the binary string will be shrunk by removing bytes. You can control the direction of resizing by providing the optional <fromLeft> parameter. By default, if the <fromLeft> parameter is not provided or set to false, the resizing will occur from the end of the binary string. If the <fromLeft> parameter is set to true, the resizing will occur from the beginning of the binary string.

Related

BinaryShrink, BinaryGrow

Example

Example of usage:

my $a = Bin("HelloWorld!");
BinarySize($a, 4);
say BinaryExpand($a, false);

my $a = Bin("HelloWorld!");
BinarySize($a, 4, 'T');
say BinaryExpand($a, false);

my $a = Bin("HelloWorld!");
BinarySize($a, 16);
say BinaryExpand($a, false);

my $a = Bin("HelloWorld!");
BinarySize($a, 16, 'T');
say BinaryExpand($a, false);

// PRINTS
// 48 65 6C 6C -- -- -- -- -- -- -- -- -- -- -- -- Hell
// 72 6C 64 21 -- -- -- -- -- -- -- -- -- -- -- -- rld!
// 48 65 6C 6C 6F 57 6F 72 6C 64 21 00 00 00 00 00 HelloWorld!.....
// 20 20 20 20 20 48 65 6C 6C 6F 57 6F 72 6C 64 21      HelloWorld!

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org