std::bitset::count
De cppreference.com
![]() |
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
size_t count() const; |
||
Devuelve el número de bits que se establecen a true .
Original:
Returns the number of bits that are set to true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Contenido |
[editar] Parámetros
(Ninguno)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Valor de retorno
número de bits que se establecen a true .
Original:
number of bits that are set to true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Ejemplo
Ejecuta este código
#include <iostream> #include <bitset> int main() { std::bitset<8> b("00010010"); std::cout << "initial value: " << b << '\n'; // find the first unset bit size_t idx = 0; while (idx < b.size() && b.test(idx)) ++idx; // continue setting bits until half the bitset is filled while (idx < b.size() && b.count() < b.size()/2) { b.set(idx); std::cout << "setting bit " << idx << ": " << b << '\n'; while (idx < b.size() && b.test(idx)) ++idx; } }
Salida:
initial value: 00010010 setting bit 0: 00010011 setting bit 2: 00010111
[editar] Ver también
devuelve el número del tamaño de bits que el bitset puede contener Original: returns the size number of bits that the bitset can hold The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) |