Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Class that holds a bitmask of variable size. More...
#include <cs_BitmaskVarSize.h>
Public Member Functions | |
BitmaskVarSize () | |
~BitmaskVarSize () | |
bool | setNumBits (uint8_t numBits) |
Set new number of bits. More... | |
bool | setBit (uint8_t bit) |
Set Nth bit. More... | |
bool | clearBit (uint8_t bit) |
Clear Nth bit. More... | |
bool | isSet (uint8_t bit) |
Check if Nth bit is set. More... | |
void | clearAllBits () |
Clear all bits. More... | |
bool | isAllBitsSet () |
Check if all bits are set. More... | |
Protected Member Functions | |
uint8_t | getNumBytes (uint8_t numBits) |
Get number of bytes required to store given number of bits. More... | |
Protected Attributes | |
uint8_t | _numBits = 0 |
uint8_t * | _bitmask = nullptr |
Bitmask. More... | |
Class that holds a bitmask of variable size.
Optimized for calling isAllBitsSet() more often than clearAllBits().
BitmaskVarSize::~BitmaskVarSize | ( | ) |
void BitmaskVarSize::clearAllBits | ( | ) |
Clear all bits.
bool BitmaskVarSize::clearBit | ( | uint8_t | bit | ) |
Clear Nth bit.
|
protected |
Get number of bytes required to store given number of bits.
bool BitmaskVarSize::isAllBitsSet | ( | ) |
Check if all bits are set.
bool BitmaskVarSize::isSet | ( | uint8_t | bit | ) |
Check if Nth bit is set.
bool BitmaskVarSize::setBit | ( | uint8_t | bit | ) |
Set Nth bit.
bool BitmaskVarSize::setNumBits | ( | uint8_t | numBits | ) |
Set new number of bits.
All bits will be cleared.
Returns true on success. Returns false when failed, new number of bits will then be 0.
|
protected |
Bitmask.
Looks like: byte 0: [ 7 6 5 4 3 2 1 0] byte 1: [15 14 13 12 11 10 9 8] byte 2: [23 22 21 20 19 18 17 16] So if you want 17 bits, then you need 3 bytes. So (17 / 8) rounded up. And to get bit 10, you need byte 1, shift by 2. So byte (10 / 8) rounded down, shifted by (10 % 8)
|
protected |