"Sputnik" help  
Sputnik Help
BinaryPadCenter(<binary>, <totalWidth>, <paddingByte>)

Description

The BinaryPadCenter function is used to pad a binary string on the left and right side with a specified padding byte, resulting in a binary string with a specified total width.

Parameters

<binary> The original binary string to be padded.
<totalWidth> The desired total width of the resulting binary string.
<paddingByte> Optional byte used for padding. If not specified, the default padding byte is 0x20 (space).

Return Value

Success: Returns a new binary string with the specified total width, padded on the left and right side.
Failure: Returns an empty binary string.

Remarks

If the <binary> string is already equal to or longer than the <totalWidth>, the function will return the original binary string unchanged.
The <paddingByte> is used to fill the space on the left and right side of the <binary> string to achieve the desired <totalWidth>. It can be any byte value, but the default padding byte is 0x20 (space).
The resulting binary string will have a length equal to <totalWidth>. If the <binary> string is shorter than <totalWidth>, the remaining space will be filled with the specified <paddingByte>.
The original binary string is not modified; instead, a new binary string is created with the padding applied.

Related

BinaryPadRight, BinaryPad

Example

Example of usage:

my $binary = BinaryFromStr("Hello");
my $paddedBoth = BinaryPad($binary, 10, @PaddingBoth);
my $paddedStart = BinaryPadLeft($binary, 10);
my $paddedEnd = BinaryPadRight($binary, 10);
my $paddedCenter = BinaryPadCenter($binary, 10);
say "'$paddedBoth'";
say "'$paddedStart'";
say "'$paddedEnd'";
say "'$paddedCenter'";

// PRINTS
// '          Hello          '
// '     Hello'
// 'Hello     '
// '  Hello   '

 


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