> Pete C. <x@x.x> wrote in message
news:%J******************@newsread2.news.pas.earth link.net... Thanks. It's for recording a group of switches (on or off).
If using std::bitset<100>, should "100" be the number of bits?
Could you give an example to set 5th bit to 1? How to check if 7th bit is
1 or 0?
#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<8> switches(0xAF); // 1010 1111
const bitset<8> MASK(0xF5); // 1111 0101
cout << "switches: " << switches << endl
<< " mask: " << MASK << endl << endl
<< " AND: " << (switches & MASK)
<< " -- turn off switches masked as 0\n"
<< " OR: " << (switches | MASK)
<< " -- turn on switches masked as 1\n"
<< " XOR: " << (switches ^ MASK)
<< " -- flip switches masked as 1"
<< endl;
}