c++ bitset test
时间: 2023-06-29 11:07:10 浏览: 116
Sure! Here's a simple example of using bitset in C++:
```c++
#include <iostream>
#include <bitset>
int main() {
std::bitset<8> bits; // create a bitset with 8 bits
// set some bits
bits.set(0);
bits.set(2);
bits.set(4);
bits.set(6);
// print the bitset
std::cout << bits << std::endl;
// flip a bit
bits.flip(2);
// print the bitset again
std::cout << bits << std::endl;
// check if a bit is set
if (bits.test(4)) {
std::cout << "Bit 4 is set!" << std::endl;
}
return 0;
}
```
This program creates a bitset with 8 bits, sets some of the bits, prints the bitset, flips one of the bits, prints the bitset again, and checks if a specific bit is set. You can compile and run this program to see the output.
阅读全文