bitset::count

Devuelve el número de bits establecidos en la secuencia de bits.

size_t count( ) const;

Valor devuelto

El número de bits establecidos en la secuencia de bits.

Ejemplo

Al compilar este ejemplo con el marcador de /Wp64 o en una plataforma de 64 bits, el compilador que excluya C4267 se generará.Para obtener más información sobre esta advertencia, vea Advertencia del compilador (nivel 3) C4267.

// bitset_count.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
    using namespace std;

    bitset<5> b1(4);

    cout << "The collection of bits in the original bitset is: ( "
         << b1 << " )" << endl;

    size_t i;
    i = b1.count();
    cout << "The number of bits in the bitset set to 1 is: "
         << i << "." << endl;

    bitset<5> fb1;
    fb1 = b1.flip();

    cout << "The collection of flipped bits in the modified bitset "
         << "is: ( " << b1 << " )" << endl;

    size_t ii;
    ii = fb1.count();
    cout << "The number of bits in the bitset set to 1 is: "
         << ii << "." << endl;
}
  
  

Requisitos

encabezado: <bitset>

espacio de nombres: std

Vea también

Referencia

bitset Class