A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd
Join the ETL community

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.
position is not checked for validity.
____________________________________________________________________________________________________

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.
position is not checked for validity.
____________________________________________________________________________________________________

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.
position is not checked for validity.

____________________________________________________________________________________________________

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::bitset<N>& lhs, etl::bitset<N>& rhs)

Swaps the contents of the two bitsets.
The bitsets must of the same size.
bitset.h