Library of Assembled Shared Sources
|
A set of simple bit manipulation functions.
This module groups simple bit manipulation functions you can use on bitfields. These bitfields can be of any type for which the bit operators like &=, |=, ... are defined. Typically, you'll use int
, char
, unsigned
, ...
The functions are split in two groups. The bit routines (with the word Bit
in their names :) and the mask routines (with the word Mask
). The groups are very alike, except in the way you address the bits to affect. With the bit group you will address one single bit at one time, and you will indicate it by its index in the bit field (i.e. bit 0 is 0x01, bit 1 is 0x02, bit 2 is 0x04, ...). With the mask group, you can address multiple bits at once by setting these bits in the mask (e.g. to address bits 0 and 2, you'll use 0x05 as mask). These mask must be of the same type of the bitfield.
With the routines you can set bits to 1; clear bits to 0; flip bits (0 becomes 1, 1 becomes 0); set, clear or flip bits if a condition is fullfilled; set a bit to a given value (0 or 1); check if a bit is set. For all these operations you'll find a function in both the bit
group as in the mask
group, except for the last operation: to check if a bit is set. In the bit
group you'll find one function checkBit which will return true if the addressed bit is set. In the mask
group you'll find two: checkMaskedAll and checkMaskedSome. the former only returns true if all bits addressed by the mask are set (an and operation), the latter already returns true if at least some of the addressed bits are set (an or operation).
Data Structures | |
struct | lass::num::lass::util::impl::BitCounter< numBytes > |
countBits helper More... | |
struct | lass::util::impl::BitCounter< numBytes > |
countBits helper More... | |
Functions | |
template<typename T> | |
void | lass::num::lass::util::setBit (T &a_bits, size_t a_bit) |
Set a bit high. | |
template<typename T> | |
void | lass::num::lass::util::clearBit (T &a_bits, size_t a_bit) |
set a bit low. | |
template<typename T> | |
void | lass::num::lass::util::flipBit (T &a_bits, size_t a_bit) |
flip state of a bit (low->high, high->low). | |
template<typename T> | |
void | lass::num::lass::util::setBitIf (T &a_bits, size_t a_bit, bool a_condition) |
set a bit high if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::num::lass::util::clearBitIf (T &a_bits, size_t a_bit, bool a_condition) |
set a bit low if (and only if) a condition is fullfilled is true. | |
template<typename T> | |
void | lass::num::lass::util::flipBitIf (T &a_bits, size_t a_bit, bool a_condition) |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low). | |
template<typename T> | |
void | lass::num::lass::util::setBitTo (T &a_bits, size_t a_bit, bool a_state) |
set a bit to a given state. | |
template<typename T> | |
bool | lass::num::lass::util::checkBit (T a_bits, size_t a_bit) |
return true if a bit is set high. | |
template<typename T> | |
void | lass::num::lass::util::setMasked (T &a_bits, const T &a_mask) |
Set masked bits high. | |
template<typename T> | |
void | lass::num::lass::util::clearMasked (T &a_bits, const T &a_mask) |
Set masked bits low. | |
template<typename T> | |
void | lass::num::lass::util::flipMasked (T &a_bits, const T &a_mask) |
flip masked bits. | |
template<typename T> | |
void | lass::num::lass::util::setMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits high if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::num::lass::util::clearMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits low if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::num::lass::util::flipMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Flip the masked bits if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::num::lass::util::setMaskedTo (T &a_bits, const T &a_mask, bool a_state) |
Set the masked bits to a given state if (and only if) a condition is fullfilled. | |
template<typename T> | |
bool | lass::num::lass::util::checkMaskedAll (T a_bits, const T &a_mask) |
Check the masked bits and return true if they are ALL set. | |
template<typename T> | |
bool | lass::num::lass::util::checkMaskedSome (T a_bits, const T &a_mask) |
Check the masked bits and return true if at least one is set. | |
template<typename T> | |
size_t | lass::num::lass::util::countBits (T bits) |
returns number of set bits in bits | |
template<typename T> | |
void | lass::util::setBit (T &a_bits, size_t a_bit) |
Set a bit high. | |
template<typename T> | |
void | lass::util::clearBit (T &a_bits, size_t a_bit) |
set a bit low. | |
template<typename T> | |
void | lass::util::flipBit (T &a_bits, size_t a_bit) |
flip state of a bit (low->high, high->low). | |
template<typename T> | |
void | lass::util::setBitIf (T &a_bits, size_t a_bit, bool a_condition) |
set a bit high if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::util::clearBitIf (T &a_bits, size_t a_bit, bool a_condition) |
set a bit low if (and only if) a condition is fullfilled is true. | |
template<typename T> | |
void | lass::util::flipBitIf (T &a_bits, size_t a_bit, bool a_condition) |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low). | |
template<typename T> | |
void | lass::util::setBitTo (T &a_bits, size_t a_bit, bool a_state) |
set a bit to a given state. | |
template<typename T> | |
bool | lass::util::checkBit (T a_bits, size_t a_bit) |
return true if a bit is set high. | |
template<typename T> | |
void | lass::util::setMasked (T &a_bits, const T &a_mask) |
Set masked bits high. | |
template<typename T> | |
void | lass::util::clearMasked (T &a_bits, const T &a_mask) |
Set masked bits low. | |
template<typename T> | |
void | lass::util::flipMasked (T &a_bits, const T &a_mask) |
flip masked bits. | |
template<typename T> | |
void | lass::util::setMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits high if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::util::clearMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Set masked bits low if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::util::flipMaskedIf (T &a_bits, const T &a_mask, bool a_condition) |
Flip the masked bits if (and only if) a condition is fullfilled. | |
template<typename T> | |
void | lass::util::setMaskedTo (T &a_bits, const T &a_mask, bool a_state) |
Set the masked bits to a given state if (and only if) a condition is fullfilled. | |
template<typename T> | |
bool | lass::util::checkMaskedAll (T a_bits, const T &a_mask) |
Check the masked bits and return true if they are ALL set. | |
template<typename T> | |
bool | lass::util::checkMaskedSome (T a_bits, const T &a_mask) |
Check the masked bits and return true if at least one is set. | |
template<typename T> | |
size_t | lass::util::countBits (T bits) |
returns number of set bits in bits | |
Variables | |
const size_t | lass::num::lass::util::impl::bitsInByte [256] |
lookup table of number of bits in a byte | |
const size_t | lass::util::impl::bitsInByte [256] |
lookup table of number of bits in a byte | |
|
inline |
Set a bit high.
a_bits | the bitfield of which a bit must be set high. |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) |
Definition at line 67 of file basic_ops.h.
|
inline |
set a bit low.
a_bits | the bitfield of which a bit must be set low. |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) |
Definition at line 81 of file basic_ops.h.
|
inline |
flip state of a bit (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) |
Definition at line 95 of file basic_ops.h.
|
inline |
set a bit high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which a bit must be set high. |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be set high, false if not. |
Definition at line 110 of file basic_ops.h.
|
inline |
set a bit low if (and only if) a condition is fullfilled is true.
a_bits | the bitfield of which a bit must be set low. |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be set low, false if not. |
Definition at line 125 of file basic_ops.h.
|
inline |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be flipped, false if not. |
Definition at line 140 of file basic_ops.h.
|
inline |
set a bit to a given state.
a_bits | the bitfield of which a bit must be set. |
a_bit | the index of the bit to be set (0 => 0x1, 1 => 0x2, ...) |
a_state | the state to which the bit must be set: true for high, false for low. |
Definition at line 155 of file basic_ops.h.
|
inline |
return true if a bit is set high.
a_bits | the bitfield of which a bit must be checked. |
a_bit | the index of the bit to be checked (0 => 0x1, 1 => 0x2, ...) |
Definition at line 170 of file basic_ops.h.
|
inline |
Set masked bits high.
a_bits | the bitfield of which some bits must be set high. |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 188 of file basic_ops.h.
|
inline |
Set masked bits low.
a_bits | the bitfield of which some bits must be set low. |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 205 of file basic_ops.h.
|
inline |
flip masked bits.
a_bits | the bitfield of which some bits must be flipped. |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 222 of file basic_ops.h.
|
inline |
Set masked bits high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set high. |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be set, false if not. |
Definition at line 240 of file basic_ops.h.
|
inline |
Set masked bits low if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set low. |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be set, false if not. |
Definition at line 258 of file basic_ops.h.
|
inline |
Flip the masked bits if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be flipped. |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be flipped, false if not. |
Definition at line 276 of file basic_ops.h.
|
inline |
Set the masked bits to a given state if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set. |
a_mask | mask indicating the bits that must be set. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_state | the state to which the bits must be set: true for high, false for low. |
Definition at line 294 of file basic_ops.h.
|
inline |
Check the masked bits and return true if they are ALL set.
a_bits | the bitfield of which some bits must be checked. |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 314 of file basic_ops.h.
|
inline |
Check the masked bits and return true if at least one is set.
a_bits | the bitfield of which some bits must be checked. |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 332 of file basic_ops.h.
|
inline |
Set a bit high.
a_bits | the bitfield of which a bit must be set high. |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) |
Definition at line 66 of file bit_manip.inl.
|
inline |
set a bit low.
a_bits | the bitfield of which a bit must be set low. |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) |
Definition at line 80 of file bit_manip.inl.
Referenced by setBitTo().
|
inline |
flip state of a bit (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) |
Definition at line 94 of file bit_manip.inl.
|
inline |
set a bit high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which a bit must be set high. |
a_bit | the index of the bit to be set high (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be set high, false if not. |
Definition at line 109 of file bit_manip.inl.
References setMasked().
Referenced by setBitTo().
|
inline |
set a bit low if (and only if) a condition is fullfilled is true.
a_bits | the bitfield of which a bit must be set low. |
a_bit | the index of the bit to be set low (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be set low, false if not. |
Definition at line 124 of file bit_manip.inl.
References clearMasked().
|
inline |
flip a bit if (and only if) a condition is fullfilled (low->high, high->low).
a_bits | the bitfield of which a bit must be flipped. |
a_bit | the index of the bit to be flipped (0 => 0x1, 1 => 0x2, ...) |
a_condition | true if the bit must be flipped, false if not. |
Definition at line 139 of file bit_manip.inl.
References flipMasked().
|
inline |
set a bit to a given state.
a_bits | the bitfield of which a bit must be set. |
a_bit | the index of the bit to be set (0 => 0x1, 1 => 0x2, ...) |
a_state | the state to which the bit must be set: true for high, false for low. |
Definition at line 154 of file bit_manip.inl.
References clearBit(), and setBitIf().
|
inline |
return true if a bit is set high.
a_bits | the bitfield of which a bit must be checked. |
a_bit | the index of the bit to be checked (0 => 0x1, 1 => 0x2, ...) |
Definition at line 169 of file bit_manip.inl.
|
inline |
Set masked bits high.
a_bits | the bitfield of which some bits must be set high. |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 187 of file bit_manip.inl.
Referenced by setBitIf(), and setMaskedIf().
|
inline |
Set masked bits low.
a_bits | the bitfield of which some bits must be set low. |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 204 of file bit_manip.inl.
Referenced by clearBitIf(), clearMaskedIf(), and setMaskedTo().
|
inline |
flip masked bits.
a_bits | the bitfield of which some bits must be flipped. |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 221 of file bit_manip.inl.
Referenced by flipBitIf(), and flipMaskedIf().
|
inline |
Set masked bits high if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set high. |
a_mask | mask indicating the bits that must be set high. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be set, false if not. |
Definition at line 239 of file bit_manip.inl.
References setMasked().
Referenced by setMaskedTo().
|
inline |
Set masked bits low if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set low. |
a_mask | mask indicating the bits that must be set low. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be set, false if not. |
Definition at line 257 of file bit_manip.inl.
References clearMasked().
|
inline |
Flip the masked bits if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be flipped. |
a_mask | mask indicating the bits that must be flipped. The high bits in the mask indicate the bits in the bitfield to be flipped, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_condition | true if the bits must be flipped, false if not. |
Definition at line 275 of file bit_manip.inl.
References flipMasked().
|
inline |
Set the masked bits to a given state if (and only if) a condition is fullfilled.
a_bits | the bitfield of which some bits must be set. |
a_mask | mask indicating the bits that must be set. The high bits in the mask indicate the bits in the bitfield to be set, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
a_state | the state to which the bits must be set: true for high, false for low. |
Definition at line 293 of file bit_manip.inl.
References clearMasked(), and setMaskedIf().
|
inline |
Check the masked bits and return true if they are ALL set.
a_bits | the bitfield of which some bits must be checked. |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 313 of file bit_manip.inl.
|
inline |
Check the masked bits and return true if at least one is set.
a_bits | the bitfield of which some bits must be checked. |
a_mask | mask indicating the bits that must be checked. The high bits in the mask indicate the bits in the bitfield to be checked, the low bits in the mask indicate the bits in the bitfield to be left untouched. |
Definition at line 331 of file bit_manip.inl.