题解 | #奇偶校验#

奇偶校验

https://www.nowcoder.com/practice/729d11d043d8448e83befa1410b694fe

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
using namespace std;

int main() {
    char x;
    while (cin >> x) { 
        int as = x;
        int count = 0;
        while(as)
        {
            count = count + ( as % 2 );
            as /= 2;
        }
        if(count % 2 == 0)
            x += 128;
        cout << bitset<8>(x) << endl;
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务