How to check if at least one bit is set in a bitset number with C++

1 Answer

0 votes
#include <bits/stdc++.h> 
 
using namespace std; 
   
int main() 
{ 
    bitset<4> bs(string("1000")); 
    
    if (bs.any()) 
        cout << "yes";
    else
        cout << "no";
    
    return 0; 
} 
 
 
 
/*
run:
 
yes
 
*/

 



answered Dec 6, 2019 by avibootz
...