#include <string.h>
#include "stdlib.h"
unsigned int char2int(char *str)
{
unsigned int count=0, ret=0
for(count = 0count<strlen(str)count++)
{
ret = ret<<1
if('0' != str[count])
{ ret+=1}
}
return ret
}
unsigned int getR(char *str)
{
unsigned int c =0
int ret = strlen(str)-1
for(c=0c <strlen(str)c++)
{if(str[c] != '0')<br/> {return ret-c}
}
}
int getRi(unsigned int num)
{
int c =0
for(num != 0c++)
{num = num>>1}
return c
}
void CRC(char *scode, char *p, char*g )
{
unsigned int iP = char2int(p)
unsigned int iG = char2int(g)
unsigned int r= getR(g)
unsigned int code = iP <<r
unsigned int yx = code
for(getRi(yx) >= getRi(iG))
{ yx = yx ^ (iG<<(getRi(yx) - getRi(iG)))}
code += yx
itoa(code,scode,2)
}
void main() //定义主函数
{
char data[8]="" , bds[8]="",code[16]=""
printf("数据:")
scanf("%s", data)
printf("表达式:")
scanf("%s", bds)
CRC(code,data,bds)
printf("编码:%s",code)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)