"Sputnik" help  
Sputnik Help
BinaryInvertBit(<binary>,<index>)

Description

The BinaryInvertBit function inverts (toggles) the value of the bit at the specified index in the <binary>.

Parameters

<binary> The binary in which to invert the bit.
<index> The index of the bit to invert (0-based).

Return Value

Success: Returns true if the bit was successfully inverted.
Failure: Returns false.

Remarks

The binary manipulation functions provided in this library allow you to work with individual bits within a binary data structure. A bit is the smallest unit of information in computing and can have two possible values: 0 or 1. The functions enable you to retrieve, set, toggle, invert, fill, and clear individual bits within a binary. In Sputnik, the binary data is stored in bytes, with each byte capable of holding 8 bits. These functions provide a convenient way to perform low-level bit manipulation operations on binary data.

Related

BinarySetBit, BinaryGetBit, BinaryClearBit, BinaryFillBit

Example

Inverting bits by flipping their state from 1 to 0 or 0 to 1:

my $binary = pack("B*", "10101101");
my $unpacked = "";
for (my $i = 0; $i < 8; $i++)
{
    BinaryInvertBit($binary, $i);
    $unpacked .= BinaryGetBit($binary, $i) ? "1" : "0";
}
say $unpacked;
// PRINTS
// 01010010

 


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