Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

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
...