"Sputnik" help  
Sputnik Help
AlignAs(<binary>, <align>, [<padRight>])

Description

Aligns a binary string to a given size. If the binary is smaller than the specified size, it will be padded to that size. If it is larger, it will remain unchanged. The optional parameter <padRight> determines whether padding occurs on the left (default) or right side.

Parameters

<binary> The binary string to be aligned.
<align> The size to which the binary should be aligned.
[<padRight>] Optional. If set to true, padding occurs on the right side. Default is false.

Return Value

Success: Returns true if the size is the boundary or was changed to the binary; false otherwise.
Failure: Returns false

Remarks

The AlignAs function is useful for aligning binary data to a specified size without trimming the data if it exceeds that size. The function returns true if the size matches the boundary or if the binary is modified; otherwise, it returns false.

Related

Bin2Hex

Example

Example of usage:

my $bin = undef;
Vec($bin, 0, 8) = 55;
printr $bin;
AlignAs($bin, 8);
printr $bin;
// Binary
// (
//     [0] => 0x37 [55] (7)
// )
// Binary
// (
//     [0] => 0x37 [55] (7)
//     [1] => 0x00 [0] (.)
//     [2] => 0x00 [0] (.)
//     [3] => 0x00 [0] (.)
//     [4] => 0x00 [0] (.)
//     [5] => 0x00 [0] (.)
//     [6] => 0x00 [0] (.)
//     [7] => 0x00 [0] (.)
// )

Align to right:

my $bin = undef;
Vec($bin, 0, 8) = 55;
printr $bin;
AlignAs($bin, 8, true);
printr $bin;
// Binary
// (
//     [0] => 0x37 [55] (7)
// )
// Binary
// (
//     [0] => 0x00 [0] (.)
//     [1] => 0x00 [0] (.)
//     [2] => 0x00 [0] (.)
//     [3] => 0x00 [0] (.)
//     [4] => 0x00 [0] (.)
//     [5] => 0x00 [0] (.)
//     [6] => 0x00 [0] (.)
//     [7] => 0x37 [55] (7)
// )

 


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