Bits

Git Source

State Variables

ONE

uint256 private constant ONE = uint256(1);

ONES

uint256 private constant ONES = type(uint256).max;

Functions

setBit

Sets the bit at the given 'index' in 'self' to '1'. Returns The modified value.

function setBit(uint256 self, uint8 index) internal pure returns (uint256);

clearBit

Sets the bit at the given 'index' in 'self' to '0'. Returns the modified value.

function clearBit(uint256 self, uint8 index) internal pure returns (uint256);

toggleBit

Sets the bit at the given 'index' in 'self' to: '1' - if the bit is '0' '0' - if the bit is '1' Returns the modified value.

function toggleBit(uint256 self, uint8 index) internal pure returns (uint256);

bit

Get the value of the bit at the given 'index' in 'self'.

function bit(uint256 self, uint8 index) internal pure returns (uint8);

bitSet

Check if the bit at the given 'index' in 'self' is set. Returns: 'true' - if the value of the bit is '1' 'false' - if the value of the bit is '0'

function bitSet(uint256 self, uint8 index) internal pure returns (bool);

bitEqual

Checks if the bit at the given 'index' in 'self' is equal to the corresponding bit in 'other'. Returns: 'true' - if both bits are '0' or both bits are '1' 'false' - otherwise

function bitEqual(uint256 self, uint256 other, uint8 index) internal pure returns (bool);

bitNot

Get the bitwise NOT of the bit at the given 'index' in 'self'.

function bitNot(uint256 self, uint8 index) internal pure returns (uint8);

bitAnd

Computes the bitwise AND of the bit at the given 'index' in 'self', and the corresponding bit in 'other', and returns the value.

function bitAnd(uint256 self, uint256 other, uint8 index) internal pure returns (uint8);

bitOr

Computes the bitwise OR of the bit at the given 'index' in 'self', and the corresponding bit in 'other', and returns the value.

function bitOr(uint256 self, uint256 other, uint8 index) internal pure returns (uint8);

bitXor

Computes the bitwise XOR of the bit at the given 'index' in 'self', and the corresponding bit in 'other', and returns the value.

function bitXor(uint256 self, uint256 other, uint8 index) internal pure returns (uint8);

bits

*Gets 'numBits' consecutive bits from 'self', starting from the bit at 'startIndex'. Returns the bits as a 'uint'. Requires that:

  • '0 < numBits <= 256'
  • 'startIndex < 256'
  • 'numBits + startIndex <= 256'*
function bits(uint256 self, uint8 startIndex, uint16 numBits) internal pure returns (uint256);

highestBitSet

Computes the index of the highest bit set in 'self'. Returns the highest bit set as an 'uint8'. Requires that 'self != 0'.

function highestBitSet(uint256 self) internal pure returns (uint8 highest);

lowestBitSet

Computes the index of the lowest bit set in 'self'. Returns the lowest bit set as an 'uint8'. Requires that 'self != 0'.

function lowestBitSet(uint256 self) internal pure returns (uint8 lowest);