How to use and, or and xor operations on bits in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

int main()
{
	int n1 = 255, n2 = 1, n_and, n_or, n_xor;

	n_and = n1 & n2;
	n_or = n1 | n2;
	n_xor = n1 ^ n2;

	cout << n1 << " AND " << n2 << " = " << n_and << endl;
	cout << n1 << " OR " << n2 << " = " << n_or << endl;
	cout << n1 << " XOR " << n2 << " = " << n_xor << endl;

	cout << endl;

	return 0;
}


/*
run:

255 AND 1 = 1
255 OR 1 = 255
255 XOR 1 = 254

*/

 



answered May 20, 2018 by avibootz
...