A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd

bitset

A fixed capacity bitset.
STL equivalent: std::bitset

etl::bitset<const size_t N>

The class inherits from etl::ibitset.
A reference to etl::ibitset may be used to access and manipulate any etl::bitset template instance.
Has a number of extensions over std::bitset. Can be considered similar to an array of bool.

Constructor

The initial state of the bitset is all clear (false).

etl::bitset<const size_t SIZE>();
etl::bitset<const size_t SIZE>(unsigned long value);
etl::bitset<const size_t SIZE>(const char* str);
The bitset is either default constructed, initialised with a numeric value, or a text string of zeros and ones.

Bit access

bool operator[](size_t position) const
Returns the boolean state of the indexed bit.

size_t count() const
Returns the number of set bits.

size_t size() const
Returns the number of bits supported by this bitset.

bool test(size_t position) const
Returns the boolean state of the indexed bit.

bool any() const
Returns true if any of the bits are set, otherwise false.

bool none() const
Returns true if none of the bits are set, otherwise false.

bool all() const
Returns true if al of the bits are set, otherwise false.

size_t find_first(bool state) const
Returns the position of the first bit in the specified state. If not found then returns N.

size_t find_next(bool state, size_t position) const
Returns the position of the next bit in the specified state, starting from position. If not found then returns N.

Bit operations

bitset<size_t N>& operator &= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator |= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator ^= (const bitset<size_t N>& rhs);
bitset<size_t N>& operator <<= (size_t shift);
bitset<size_t N>& operator >>= (size_t shift);
bool operator == (const bitset<size_t N>& rhs);
bool operator != (const bitset<size_t N>& rhs);

Non-member functions

void swap(etl::bitst<N>& lhs, etl::bitset<N>& rhs)
Swaps the contents of the two bitsets.
The bitsets must of the same size.
bitset.h