How to initialize bitset with bits in C++

5 Answers

0 votes
#include <bits/stdc++.h> 
 
using namespace std; 
   
int main() 
{ 
    bitset<4> bs1(string("1100")); 
    bitset<6> bs2(string("101101")); 

    cout << bs1 << endl;
    cout << bs2 << endl;

    return 0; 
} 
 
 
 
/*
run:
 
1100
101101
 
*/

 



answered Dec 6, 2019 by avibootz
0 votes
#include <bits/stdc++.h> 
  
using namespace std; 
    
int main() 
{ 
    string s = "100110"; 
    bitset<6> bs(s); 
 
    cout << bs << endl;
 
    return 0; 
} 
  
  
  
/*
run:
  
100110
  
*/

 



answered Dec 7, 2019 by avibootz
0 votes
#include <bits/stdc++.h> 
  
using namespace std; 
    
int main() 
{ 
    string s = "1101"; 
    bitset<6> bs(s, 1);   
 
    cout << bs << endl;
 
    return 0; 
} 
  
  
  
/*
run:
  
000101
  
*/

 



answered Dec 7, 2019 by avibootz
0 votes
#include <bits/stdc++.h> 
  
using namespace std; 
    
int main() 
{ 
    string s = "11101"; 
    bitset<6> bs(s, 2, 3);   
 
    cout << bs << endl;
 
    return 0; 
} 
  
  
  
/*
run:
  
000101
  
*/

 



answered Dec 7, 2019 by avibootz
0 votes
#include <bits/stdc++.h> 
  
using namespace std; 
    
int main() 
{ 
    bitset<6> bs(3);   
 
    cout << bs << endl;
 
    return 0; 
} 
  
  
  
/*
run:
  
000011
  
*/

 



answered Dec 7, 2019 by avibootz

Related questions

1 answer 272 views
1 answer 269 views
1 answer 324 views
1 answer 258 views
258 views asked Dec 6, 2019 by avibootz
1 answer 276 views
1 answer 266 views
266 views asked Apr 18, 2018 by avibootz
...