How to check whether a bit at a given index is set or not in a bitset with C++

1 Answer

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

 



answered Dec 7, 2019 by avibootz
...