题目1197:奇偶校验

点击打开链接

/*
      时间:2014.01.16.7.20 
     网址:http://ac.jobdu.com/problem.php?pid=1197 
	目的:题目1197:奇偶校验 
*/
#include <stdio.h>
#include <string.h>
main(int i,int j,int k,int asc)
{
	char s[101];
	int bin[8];
	int cnt;
	while(gets(s))
	{
		for(i = 0,cnt=0,memset(bin,0,sizeof(int)*8);s[i]; ++i,cnt=0,memset(bin,0,sizeof(int)*8))
		{
			for(asc = s[i],j=0;asc != 0; j++)
			{
				bin[j] = asc%2;
				asc%2&&++cnt;
				asc>>=1;//移位 
			}
			cnt%2==0&&(bin[7]=1);//求最高位的奇校验 
			for(k=7;k>=0;printf("%d",bin[k]),k--);//倒着输出 
			printf("\n"); 
		}	
	}
	return 0;
}
/*
输出结果 
-------------------------
3			思路: 1.运用了短编程的思想 
10110011		   2.运用短除的方法,移位的思想 
3a				   3. 
10110011
01100001
-------------------------
*/ 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值