Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bitset Operators
//bitset operators /* 'A ^ B' is true iff at least one is true but NOT both A and B are true. 'A | B' is true iff at least one is true or both A and B are true. 'A & B' is true iff both 'A' and 'B' are true. */ #include <iostream> #include <bitset> #include <string> using namespace std; int main() { string sb1 = "00001011"; string sb2 = "00001010"; bitset<8>b1(sb1); bitset<8>b2(sb2); bitset<8>b2a; bitset<8>nb1(~b1); cout << "\nLogical And \'&\' Operator\n\n"; b2a = b2; cout << "b2:\t\t" << b2a << "\n"; cout << "b1:\t\t" << b1 << "\n"; b2a &= b1; cout << "b2 &= b1:\t" << b2a << "\n\n"; b2a = b2; // reset b2a cout << "b2:\t\t" << b2a << "\n"; cout << "~b1:\t\t" << nb1 << "\n"; b2a &= nb1; cout << "b2 &= ~b1:\t" << b2a << "\n\n"; cout << "Logical OR \'|\' Operator\n\n"; b2a = b2; cout << "b1:\t\t" << b1 << "\n"; cout << "b2:\t\t" << b2a << "\n"; b2a |= b1; cout << "b2 |= b1:\t" << b2a << "\n\n"; b2a = b2; cout << "b2:\t\t" << b2a << "\n"; cout << "~b1:\t\t" << nb1 << "\n"; b2a |= nb1; cout << "b2 |= ~b1:\t" << b2a << "\n\n"; cout << "Logical XOR \'^\' Operator\n\n"; b2a = b2; cout << "b1:\t\t" << b1 << "\n"; cout << "b2:\t\t" << b2a << "\n"; b2a ^= b1; cout << "b2 ^= b1:\t" << b2a << "\n\n"; b2a = b2; cout << "b2:\t\t" << b2a << "\n"; cout << "~b1:\t\t" << nb1 << "\n"; b2a ^= nb1; cout << "b2 ^= ~b1:\t" << b2a << "\n\n"; }
run
|
edit
|
history
|
help
0
Day3
pranav pandey
WeekAgenda2
Test1
SEJM BLURWA
1028D
Couting number of substring occurances in C++
RecursiveFact
Minimum Vertices to Traverse Directed Graph
cotton farm 0.0.1.0