Library for bit manipulation.
Loading...
Searching...
No Matches
Library for bit manipulation.

Typedefs

template<typename... Ts>
using org::ttldtor::bits::Max = detail::MaxImpl<Ts...>::Type
 Returns max type by size (first is better)
 

Functions

template<std::integral ValueType, std::integral ShiftType>
constexpr ValueType org::ttldtor::bits::sar (ValueType value, ShiftType shift) noexcept
 Performs a right arithmetic bit shift operation (>> in Java, C, etc.).
 
template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
constexpr ValueType org::ttldtor::bits::leftArithmeticShift (ValueType value, UnsignedShiftType shift) noexcept
 Performs a left arithmetic bit shift operation (sal, << in Java, C, etc.).
 
template<std::integral ValueType, std::signed_integral SignedShiftType>
constexpr ValueType org::ttldtor::bits::leftArithmeticShift (ValueType value, SignedShiftType shift) noexcept
 Performs a left arithmetic bit shift operation (sal, << in Java, C, etc.).
 
template<std::integral ValueType, std::integral ShiftType>
constexpr ValueType org::ttldtor::bits::sal (ValueType value, ShiftType shift) noexcept
 Performs a left arithmetic bit shift operation (<< in Java, C, etc.).
 
template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
constexpr ValueType org::ttldtor::bits::rightArithmeticShift (ValueType value, UnsignedShiftType shift) noexcept
 Performs a right arithmetic bit shift operation (sar, >> in Java, C, etc.).
 
template<std::integral ValueType, std::signed_integral SignedShiftType>
constexpr ValueType org::ttldtor::bits::rightArithmeticShift (ValueType value, SignedShiftType shift) noexcept
 Performs a right arithmetic bit shift operation (sar, >> in Java, C, etc.).
 
template<std::integral ValueType, std::integral ShiftType>
constexpr ValueType org::ttldtor::bits::shr (ValueType value, ShiftType shift) noexcept
 Performs a right logical bit shift operation (>>> in Java).
 
template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
constexpr ValueType org::ttldtor::bits::leftLogicalShift (ValueType value, UnsignedShiftType shift) noexcept
 Performs a left logical bit shift operation (shl, <<<).
 
template<std::integral ValueType, std::integral SignedShiftType>
constexpr ValueType org::ttldtor::bits::leftLogicalShift (ValueType value, SignedShiftType shift) noexcept
 Performs a left logical bit shift operation (shl, <<<).
 
template<std::integral ValueType, std::integral ShiftType>
constexpr ValueType org::ttldtor::bits::shl (ValueType value, ShiftType shift) noexcept
 Performs a left logical bit shift operation (shl, <<<).
 
template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
constexpr ValueType org::ttldtor::bits::rightLogicalShift (ValueType value, UnsignedShiftType shift) noexcept
 Performs a right logical bit shift operation (shr, >>> in Java).
 
template<std::integral ValueType, std::signed_integral SignedShiftType>
constexpr ValueType org::ttldtor::bits::rightLogicalShift (ValueType value, SignedShiftType shift) noexcept
 Performs a right logical bit shift operation (shr, >>> in Java).
 
template<std::integral FirstType, std::integral SecondType>
constexpr FirstType org::ttldtor::bits::andOp (FirstType first, SecondType second) noexcept
 Performs a bitwise AND operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.
 
template<std::integral FirstType, std::integral SecondType>
constexpr FirstType org::ttldtor::bits::orOp (FirstType first, SecondType second) noexcept
 Performs a bitwise OR operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.
 
template<std::integral FirstType, std::integral SecondType>
constexpr FirstType org::ttldtor::bits::xorOp (FirstType first, SecondType second) noexcept
 Performs a bitwise XOR operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.
 
template<std::unsigned_integral T>
constexpr bool org::ttldtor::bits::bitsAreSet (T sourceBits, T bitMaskToCheck)
 Determines if the specified bits are set in the source value.
 
template<std::integral SourceBitsType, std::integral BitMaskType>
constexpr bool org::ttldtor::bits::bitsAreSet (SourceBitsType sourceBits, BitMaskType bitMaskToCheck)
 Determines if the specified bits are set in the source value.
 
template<std::unsigned_integral T>
constexpr T org::ttldtor::bits::setBits (T sourceBits, T bitMaskToSet)
 Sets specific bits in the source value using a bitmask.
 
template<std::integral SourceBitsType, std::integral BitMaskType>
constexpr SourceBitsType org::ttldtor::bits::setBits (SourceBitsType sourceBits, BitMaskType bitMaskToSet)
 Sets specific bits in the source value using a bitmask.
 
template<std::unsigned_integral T>
constexpr T org::ttldtor::bits::resetBits (T sourceBits, T bitMaskToReset)
 Resets (clears) specific bits in a bitmask.
 
template<std::integral SourceBitsType, std::integral BitMaskType>
constexpr SourceBitsType org::ttldtor::bits::resetBits (SourceBitsType sourceBits, BitMaskType bitMaskToReset)
 Resets (clears) specific bits in a bitmask.
 

Detailed Description

Function Documentation

◆ andOp()

template<std::integral FirstType, std::integral SecondType>
FirstType org::ttldtor::bits::andOp ( FirstType first,
SecondType second )
constexprnoexcept

Performs a bitwise AND operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.

Template Parameters
FirstTypeThe type of the first argument.
SecondTypeThe type of the second argument.
Parameters
firstThe first operand of type FirstType.
secondThe second operand of type SecondType.
Returns
The result of the bitwise AND operation, cast to type FirstType.

◆ bitsAreSet() [1/2]

template<std::integral SourceBitsType, std::integral BitMaskType>
bool org::ttldtor::bits::bitsAreSet ( SourceBitsType sourceBits,
BitMaskType bitMaskToCheck )
constexpr

Determines if the specified bits are set in the source value.

Template Parameters
SourceBitsTypeThe type of the source bits (e.g., an integer type).
BitMaskTypeThe type of the bit mask (e.g., an integer type).
Parameters
sourceBitsThe value to check for the presence of specific bits.
bitMaskToCheckThe mask of bits to check against the source value.
Returns
true if the specified bits are set in the source value.

◆ bitsAreSet() [2/2]

template<std::unsigned_integral T>
bool org::ttldtor::bits::bitsAreSet ( T sourceBits,
T bitMaskToCheck )
constexpr

Determines if the specified bits are set in the source value.

Template Parameters
Tthe type of arguments.
Parameters
sourceBitsThe value to check for the presence of specific bits.
bitMaskToCheckThe mask of bits to check against the source value.
Returns
true if the specified bits are set in the source value.

◆ leftArithmeticShift() [1/2]

template<std::integral ValueType, std::signed_integral SignedShiftType>
ValueType org::ttldtor::bits::leftArithmeticShift ( ValueType value,
SignedShiftType shift )
constexprnoexcept

Performs a left arithmetic bit shift operation (sal, << in Java, C, etc.).

The shift is signed.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a right arithmetic shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
SignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ leftArithmeticShift() [2/2]

template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
ValueType org::ttldtor::bits::leftArithmeticShift ( ValueType value,
UnsignedShiftType shift )
constexprnoexcept

Performs a left arithmetic bit shift operation (sal, << in Java, C, etc.).

The shift is unsigned.

The result of the shift will be of the same type as the value being shifted. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
UnsignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ leftLogicalShift() [1/2]

template<std::integral ValueType, std::integral SignedShiftType>
ValueType org::ttldtor::bits::leftLogicalShift ( ValueType value,
SignedShiftType shift )
constexprnoexcept

Performs a left logical bit shift operation (shl, <<<).

The shift is signed.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a right logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
SignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ leftLogicalShift() [2/2]

template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
ValueType org::ttldtor::bits::leftLogicalShift ( ValueType value,
UnsignedShiftType shift )
constexprnoexcept

Performs a left logical bit shift operation (shl, <<<).

The shift is unsigned.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a right logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
UnsignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ orOp()

template<std::integral FirstType, std::integral SecondType>
FirstType org::ttldtor::bits::orOp ( FirstType first,
SecondType second )
constexprnoexcept

Performs a bitwise OR operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.

Template Parameters
FirstTypeThe type of the first argument.
SecondTypeThe type of the second argument.
Parameters
firstThe first operand of type FirstType.
secondThe second operand of type SecondType.
Returns
The result of the bitwise OR operation, cast to type FirstType.

◆ resetBits() [1/2]

template<std::integral SourceBitsType, std::integral BitMaskType>
SourceBitsType org::ttldtor::bits::resetBits ( SourceBitsType sourceBits,
BitMaskType bitMaskToReset )
constexpr

Resets (clears) specific bits in a bitmask.

Template Parameters
SourceBitsTypeThe type of the source bits (e.g., an integer type).
BitMaskTypeThe type of the bit mask (e.g., an integer type).
Parameters
sourceBitsThe original bitmask containing the bits to modify.
bitMaskToResetThe bitmask specifying the bits to reset.
Returns
The resulting value after resetting the specified bits.

◆ resetBits() [2/2]

template<std::unsigned_integral T>
T org::ttldtor::bits::resetBits ( T sourceBits,
T bitMaskToReset )
constexpr

Resets (clears) specific bits in a bitmask.

Template Parameters
TThe type of the source bits and the bitmask. Should be an integral type.
Parameters
sourceBitsThe original bitmask containing the bits to modify.
bitMaskToResetThe bitmask specifying the bits to reset.
Returns
The resulting value after resetting the specified bits.

◆ rightArithmeticShift() [1/2]

template<std::integral ValueType, std::signed_integral SignedShiftType>
ValueType org::ttldtor::bits::rightArithmeticShift ( ValueType value,
SignedShiftType shift )
constexprnoexcept

Performs a right arithmetic bit shift operation (sar, >> in Java, C, etc.).

The shift is signed. The sign bit is extended to preserve the signedness of the number.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a left arithmetic shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then, if the value is negative (a signed integer type), -1 will be returned, and if positive, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
SignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ rightArithmeticShift() [2/2]

template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
ValueType org::ttldtor::bits::rightArithmeticShift ( ValueType value,
UnsignedShiftType shift )
constexprnoexcept

Performs a right arithmetic bit shift operation (sar, >> in Java, C, etc.).

The shift is unsigned. The sign bit is extended to preserve the signedness of the number.

The result of the shift will be of the same type as the value being shifted. If the shift size is greater than or equal to the number of bits in the shifted value, then, if the value is negative (a signed integer type), -1 will be returned, and if positive, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
UnsignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ rightLogicalShift() [1/2]

template<std::integral ValueType, std::signed_integral SignedShiftType>
ValueType org::ttldtor::bits::rightLogicalShift ( ValueType value,
SignedShiftType shift )
constexprnoexcept

Performs a right logical bit shift operation (shr, >>> in Java).

The shift is signed. Fills the left bits by zero.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a left logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
SignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ rightLogicalShift() [2/2]

template<std::integral ValueType, std::unsigned_integral UnsignedShiftType>
ValueType org::ttldtor::bits::rightLogicalShift ( ValueType value,
UnsignedShiftType shift )
constexprnoexcept

Performs a right logical bit shift operation (shr, >>> in Java).

The shift is unsigned. Fills the left bits by zero.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a left logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
UnsignedShiftTypeThe type of shift
Parameters
valueThe value to be shifted
shiftThe shift in bits
Returns
The shifted value

◆ sal()

template<std::integral ValueType, std::integral ShiftType>
ValueType org::ttldtor::bits::sal ( ValueType value,
ShiftType shift )
constexprnoexcept

Performs a left arithmetic bit shift operation (<< in Java, C, etc.).

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a right arithmetic shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
ShiftTypeThe type of shift
Parameters
valueThe value to be shifted.
shiftThe shift in bits
Returns
The shifted value

◆ sar()

template<std::integral ValueType, std::integral ShiftType>
ValueType org::ttldtor::bits::sar ( ValueType value,
ShiftType shift )
constexprnoexcept

Performs a right arithmetic bit shift operation (>> in Java, C, etc.).

The sign bit is extended to preserve the signedness of the number.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a left arithmetic shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then, if the value is negative (a signed integer type), -1 will be returned, and if positive, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
ShiftTypeThe type of shift
Parameters
valueThe value to be shifted.
shiftThe shift in bits
Returns
The shifted value

◆ setBits() [1/2]

template<std::integral SourceBitsType, std::integral BitMaskType>
SourceBitsType org::ttldtor::bits::setBits ( SourceBitsType sourceBits,
BitMaskType bitMaskToSet )
constexpr

Sets specific bits in the source value using a bitmask.

Template Parameters
SourceBitsTypeThe type of the source bits (e.g., an integer type).
BitMaskTypeThe type of the bit mask (e.g., an integer type).
Parameters
sourceBitsThe original bits to modify.
bitMaskToSetThe bitmask representing the bits to be set.
Returns
The resulting value after setting the specified bits.

◆ setBits() [2/2]

template<std::unsigned_integral T>
T org::ttldtor::bits::setBits ( T sourceBits,
T bitMaskToSet )
constexpr

Sets specific bits in the source value using a bitmask.

Template Parameters
TThe type of arguments.
Parameters
sourceBitsThe original bits to modify.
bitMaskToSetThe bitmask representing the bits to be set.
Returns
The resulting value after setting the specified bits.

◆ shl()

template<std::integral ValueType, std::integral ShiftType>
ValueType org::ttldtor::bits::shl ( ValueType value,
ShiftType shift )
constexprnoexcept

Performs a left logical bit shift operation (shl, <<<).

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a right logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
ShiftTypeThe type of shift
Parameters
valueThe value to be shifted.
shiftThe shift in bits
Returns
The shifted value

◆ shr()

template<std::integral ValueType, std::integral ShiftType>
ValueType org::ttldtor::bits::shr ( ValueType value,
ShiftType shift )
constexprnoexcept

Performs a right logical bit shift operation (>>> in Java).

Performs a right logical bit shift operation (shr, >>> in Java).

Fills the left bits by zero.

The result of the shift will be of the same type as the value being shifted. If the shift is a negative number of bits, then a left logical shift will be performed. If the shift size is greater than or equal to the number of bits in the shifted value, then 0 will be returned.

Template Parameters
ValueTypeThe type of value
ShiftTypeThe type of shift
Parameters
valueThe value to be shifted.
shiftThe shift in bits
Returns
The shifted value

◆ xorOp()

template<std::integral FirstType, std::integral SecondType>
FirstType org::ttldtor::bits::xorOp ( FirstType first,
SecondType second )
constexprnoexcept

Performs a bitwise XOR operation between two values of possibly different types and ensures the result is cast back to the type of the first argument.

Template Parameters
FirstTypeThe type of the first argument.
SecondTypeThe type of the second argument.
Parameters
firstThe first operand of type FirstType.
secondThe second operand of type SecondType.
Returns
The result of the bitwise XOR operation, cast to type FirstType.