A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove
Support the development
of the ETL
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.
____________________________________________________________________________________________________
Types

span_type      A mutable span type
const_span_type A non-mutable span type
element_t       The type used as the internal storage for a bitset.
                By default, this is a uint_least8_t.
                To  change this, define ETL_BITSET_ELEMENT_TYPE as an alternative type.

                #define ETL_BITSET_ELEMENT_TYPE uint32_t
____________________________________________________________________________________________________
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.
____________________________________________________________________________________________________
Modifiers

etl::ibitset& set();
Set all bits.
____________________________________________________________________________________________________
etl::ibitset& set(const char* str);
Set with a text string of zeros and ones.
____________________________________________________________________________________________________
etl::ibitset& set(size_t position, bool value = true);
Set a position to a one or zero, default one.
____________________________________________________________________________________________________
etl::ibitset& reset();
Reset all bits.
____________________________________________________________________________________________________
etl::ibitset& reset(size_t position);
Set a position to a zero.
____________________________________________________________________________________________________
etl::ibitset& from_string(const char*);
etl::ibitset& from_string(const wchar_t*);
etl::ibitset& from_string(const char16_t*);
etl::ibitset& from_string(const char32_t*);
The bitset is built from a string of  '0' and '1' characters.
____________________________________________________________________________________________________
Access

template <typename T>
T value() const
Returns the value corresponding to the bitset.
T specifies the integral type to convert to.

If called on an etl::bitset and the type is too small to contain the bitset size, a compile error will result.
If called on an etl::ibitset reference and the type is too small to contain the bitset size, a zero will be returned and
an optional exception/assert/error call will be emitted.
____________________________________________________________________________________________________

etl::ibitset::span_type span()
etl::ibitset::const_span_type span() const
Returns an etl::span of the underlying binary data.
The span is ordered LSB to MSB.
____________________________________________________________________________________________________
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 ibitset::npos.
____________________________________________________________________________________________________
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
ibitset::npos.
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 be the same size.
bitset.h