运算符

运算符有很多种。
下面是一个按位运算的小例子

#include "stdafx.h"
#include "iostream"
#include "string"
#include "bitset"
using namespace std;

int main()
{
	cout << "please input a bool numbers : " << endl;
	bool inputnumber1 = false;
	cin >> inputnumber1;
	bool inputnumber2 = false;
	cin >> inputnumber2;
	bitset<8> InputBits1(inputnumber1);
	bitset<8> InputBits2(inputnumber2);
	cout << "inputnumber1 in binary is " << InputBits1<<endl;
	cout << "inputnumber2 in binary is " << InputBits2<<endl;
	bitset<8> InputBitsAnd = (inputnumber1&inputnumber2);
	bitset<8> InputBitsOR = (inputnumber1|inputnumber2);
	bitset<8> InputBitsXOR = (inputnumber1^inputnumber2);
	cout << "InputBitsAnd in binary is " << InputBitsAnd<<endl;
	cout << "InputBitsOR in binary is " << InputBitsOR<<endl;
	cout << "InputBitsXOR in binary is " << InputBitsXOR<<endl;
	system("pause");
	return 0;
}


运行结果如下
在这里插入图片描述
注意:
1 按位运算时要运用头文件 #include bitset
2 xor异或与or不同的是只有两个不相同时才为1,or只要有一个为True,输出的结果为true.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值