| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 642 人关注过本帖
标题:c++编程的一个关于余式排序的问题(crc)
只看楼主 加入收藏
kinkey007
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-1-26
收藏
 问题点数:0 回复次数:1 
c++编程的一个关于余式排序的问题(crc)

我抽到这样的一个课题:

题目:分析所有10位二进制信息对应的CRC码。生成多项式x8+x2+x+1
环境要求:Windows95/98/2000/XP/dos
功能要求:要编写程序;要对相等余式分类统计。


首先是要所有的10位二进制信息,
我的一个自程序是:
char str[1023];
int j=1023;
for(j=1023;j>=0;j--)
{itoa(j,str,2);
}
把十进制强制成二进制...

生成多项式x8+x2+x+1好办
就是
char crc[9]={1, 0, 0, 0, 0, 0, 1, 1, 1 }

之后的求余式和对相等余式分类统计就不知道了,


目前我的水平限于看懂程序,要我自己编程还真头疼啊
望高手解救!!

搜索更多相关主题的帖子: crc 
2007-01-26 19:42
kinkey007
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-1-26
收藏
得分:0 

我在网上搜索到一个相关的程序
题目是:计算xk+1除CRC-32后的余式,k从1到32768
环境要求:Windows95/98/2000/XP/dos
功能要求:要编写程序;要按余式的次数、为零与否分类统计。

程序:#include "stdlib.h"
#include "string.h"
#include "stdio.h"
void main()
{
int result[33];
//char c;
bool flag=0;
//结果数组初始化
for(int i=0; i<33; i++)
result[i]=0;
//CRC-32 = X32 + X26 + X23 + X22 + X16 + X11 + X10 + X8 + X7 + X5 + X4 + X2 + X1 + X0
char crc32[33]={1,
0, 0, 0, 0,
0, 1, 0, 0,
1, 1, 0, 0,
0, 0, 0, 1,
0, 0, 0, 0,
1, 1, 0, 1,
1, 0, 1, 1,
0, 1, 1, 1};
//这个是t(x)=X^K+1
for(unsigned int k=1;k<=32768;k++)
{
char *remainder = new char[k + 1 + 32];
//char *s = new char[k + 1 + 32];
//原型:extern void *memset(void *buffer, int c, int count);
//功能:把buffer所指内存区域的前count个字节设置成字符c;
//说明:返回指向buffer的指针.
memset(remainder, 0, sizeof(char)*(k + 1+32));
//memset(s, 0, sizeof(char)*(k + 1+32));
remainder[0] = 1;
remainder[k] = 1;
//flag = 0;
//计算余式,余式按高位到低位的顺序存储在remainder[k]……remainder[k+32]中
unsigned int q = 0;
int zjw = 0;
while (q <= k + 1 - 33 + 32)
{
int i = 0;
if (zjw == 0)
for (i = 0; i <= 32; i++)
if (remainder[i + q] > crc32[i])
break;
else
if (remainder[i + q] < crc32[i])
{
i = 33;
break;
}
// 各位分别进行模2加运算
if (i <= 32)
{
zjw = 0;
//s[q + 32] = 1;
for (i = 32; i >= 0; i--)
{
if ((remainder[i + q] == 1 && crc32[i] == 1) ||
(remainder[i + q] == 0 && crc32[i] == 0))
remainder[i + q] = 0;
else
remainder[i + q] = 1;
}
}
else
{
zjw = remainder[q];
}
q++;
}
//确定余式的最高位数
int j=k,count=0;
while(remainder[j]==0)
{
j++;
if(count==32)
{
//能够整除的情况不统计在内
flag = 1;
break;
}
count++;
}
//在每次循环内更新结果
if(flag==0)
result[32-count]++;
free(remainder);
//free(s);
}
//输出最终结果
for(i=0; i<=32; i++)
printf("最高%2d次:%6d个\n",i,result[i]);
}
//scanf(&c);

怎么把这个程序修改成适合我的题目意思的啊,求各位大哥指教
小女子在这里谢过了

2007-01-27 15:53
快速回复:c++编程的一个关于余式排序的问题(crc)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011486 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved