c语言偶校验算法程序,C语言--偶校验---位检测

#include

//数据结构体

struct receiveData

{

unsigned char cmd;//命令标志

unsigned char cmd_info;//命令信息

unsigned char option_first;//可选择的信息1

unsigned char option_second;//可选择的信息2

unsigned char option_third;//可选择的信息1

unsigned char option_four;//可选择的信息2

unsigned char check;//校验

unsigned char end;//结束标志 暂时定位 0A 表示回车

}receData={0x20,0xff,0xef,0x24,0x28,0x01,0x00,0x00};

struct receiveData *stu=&receData;

/*******************************************************************************

*名称:LPC_Calculate_Parity()

*功能:偶校验函数 返回1表示stu中有奇数个1;返回0则表示stu中正好有偶数个1

*******************************************************************************/

char LPC_Calculate_Parity(struct receiveData *str)

{

char i=0,j=0,sum=0,check[6]={0};

for(i=0;i<6;i++)

{

switch(i)

{

case 0:for(j=0;j<8;j++){if(((*str).cmd&(1<

case 1:for(j=0;j<8;j++){if(((*str).cmd_info&(1<

case 2:for(j=0;j<8;j++){if(((*str).option_first&(1<

case 3:for(j=0;j<8;j++){if(((*str).option_second&(1<

case 4:for(j=0;j<8;j++){if(((*str).option_third&(1<

case 5:for(j=0;j<8;j++){if(((*str).option_four&(1<

}

sum+=check[i];

printf("%d\n",check[i]);

}

if(sum%2==1)

return 1;

else

return 0;

}

void main()

{

LPC_Calculate_Parity(stu);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值