题解 | 奇偶校验

#include <iostream>
#include <string>
#include <bitset>
using namespace std;
char parity_check(char c) {
	char check=1,temp = c;
	while (temp != 0) {
		check ^= (temp&1);
		temp>>=1;
	}
	return c+(check << 7);
}
int main() {
	string str;
	while (cin >> str) {
		for (int i = 0; i < str.length(); i++) {
			cout << bitset<8>(parity_check(str[i])) << endl;
		}
	}
}

全部评论

相关推荐

07-09 15:55
门头沟学院 Java
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
练习生懒羊羊:开飞机把这个公司创飞吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务