How to count the number of set bits in a bitset with C++

1 Answer

0 votes
#include <bits/stdc++.h> 
 
using namespace std; 
   
int main() 
{ 
    bitset<8> bs(string("10001100")); 
    
    cout << bs.count(); 
    
    return 0; 
} 
 
 
 
/*
run:
 
3
 
*/

 



answered Dec 6, 2019 by avibootz

Related questions

1 answer 167 views
1 answer 159 views
1 answer 193 views
193 views asked Jul 17, 2018 by avibootz
1 answer 226 views
226 views asked Jul 16, 2018 by avibootz
1 answer 173 views
...