#include <bitset> #include <climits> #include <iostream> #include <string> int main() { // empty constructor (1) std::bitset<8> b1; // [0,0,0,0,0,0,0,0] // unsigned long long constructor (2) std::bitset<8> b2(42); // [0,0,1,0,1,0,1,0] std::bitset<70> bl(ULLONG_MAX); // [0,0,0,0,0,0,1,1,1,...,1,1,1] in C++11 std::bitset<8> bs(0xfff0); // [1,1,1,1,0,0,0,0] // string constructor (3) std::string bit_string = "110010"; std::bitset<8> b3(bit_string); // [0,0,1,1,0,0,1,0] std::bitset<8> b4(bit_string, 2); // [0,0,0,0,0,0,1,0] std::bitset<8> b5(bit_string, 2, 3); // [0,0,0,0,0,0,0,1] // string constructor using custom zero/one digits (3) std::string alpha_bit_string = "aBaaBBaB"; std::bitset<8> b6(alpha_bit_string, 0, alpha_bit_string.size(), 'a', 'B'); // [0,1,0,0,1,1,0,1] // char* constructor using custom digits (5) std::bitset<8> b7("XXXXYYYY", 8, 'X', 'Y'); // [0,0,0,0,1,1,1,1] std::cout << "b1: " << b1 << "\nb2: " << b2 << "\nbl: " << bl << "\nbs: " << bs << "\nb3: " << b3 << "\nb4: " << b4 << "\nb5: " << b5 << "\nb6: " << b6 << "\nb7: " << b7 << '\n'; }
b1: 00000000 b2: 00101010 bl: 0000001111111111111111111111111111111111111111111111111111111111111111 bs: 11110000 b3: 00110010 b4: 00000010 b5: 00000001 b6: 01001101 b7: 00001111
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4