GF2::Vector — Bit Counts
Counts the number of set/unset elements in a bit-vector.
constexpr std::size_t count() const; (1)
constexpr std::size_t count1() const; (2)
constexpr std::size_t count0() const; (3)
constexpr bool parity() const; (4)
| 1 | Returns the number of elements in the bit-vector that are set to 1. |
| 2 | Returns the number of elements in the bit-vector that are set to 1 (synonym for count()) |
| 3 | Returns the number of elements in the bit-vector that are unset at 0. |
| 4 | Returns count() % 2--the number of set elements mod 2. |
Example
#include <GF2/GF2.h>
int main()
{
GF2::Vector<> v1("00000");
GF2::Vector<> v2("01010");
GF2::Vector<> v3("11111");
std::cout
<< "Vector\t" << "count1\t" << "count0\t" << "parity\n"
<< v1 << '\t' << v1.count1() << '\t' << v1.count0() << '\t' << v1.parity() << '\n'
<< v2 << '\t' << v2.count1() << '\t' << v2.count0() << '\t' << v2.parity() << '\n'
<< v3 << '\t' << v3.count1() << '\t' << v3.count0() << '\t' << v3.parity() << '\n';
}
Output
Vector count1 count0 parity
00000 0 5 0
01010 2 3 0
11111 5 0 1
See Also