1、计算机网络实验1杭 州 电 子 科 技 大 学实 验 报 告学生姓名:韩民杨 学 号: 指导教师:吴端坡实验地点:1#108 实验时间:2015-4-24一、实验室名称:1#108二、实验项目名称:计算机网络实验1Coding on error dectecting algorithms(C+)三、实验学时:四、实验原理:C+编程五、实验目的:利用C+编程CRC16校验及奇偶校验六、实验内容:Coding on error dectecting algorithms(C+)1. Cyclic redundancy checkUsing the polynomials below to enco
2、de random generated data stream (40-100bits). Show the FEC, and encoded data frame.CRC-4x4+x+1ITU CRC-16x16+x15+x2+1IBM SDLCCRC-32x32+x26+x23+.+x2+x+1ZIP, RAR, IEEE 802 LAN/FDDI, IEEE 1394, PPP-FCSFor the error patter listed below, what the conclusion does the receiver get Can the receiver find the
3、errorsCaseError patternNo error00000000One error1000.000Two errors100.001Random errorsRandom error pattern2. Parity check Using even or odd parity check on random generated data stream (8-20bits).Show encoded data frame.For the error patter listed below, what the conclusion does the receiver get Can
4、 the receiver find the errorsCaseError patternNo error00000000One error1000.000Two errors100.001七、实验器材(设备、元器件): PC机一台,装有C+集成开发环境。八、实验步骤:#include#include#include#include#include #include #define NO_ERROR 1#define ONE_ERROR 2#define TWO_ERROR 3#define RANDOM_ERROR 4#define RESULT 1#define CRC 0#define
5、 Parity 0#define check 1int flag_parity;000 Two errors 100.001 Random errors Random error pattern*/ if(channel_way = NO_ERROR) char *result = NULL; int flagg=0; printf(信道中传输数据:); for(int f =0;flength*8+len_d-1 ;f+) printf(%c,message_inputf); printf(n); printf(正在检错中.n); printf(检错结果:); fflush(stdin);
6、result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d); for(int i = 0;i len_d-1;i+) printf(%c,*result); if(*result) - 48 != 0) printf(n error! n); flagg =1; break; result+=1; if(flagg = 0) printf(n no error! n); if(channel_way = ONE_ERROR) char *result = NULL; message_input0 = (mes
7、sage_input0 - 48)(1-48) + 48; printf(信道中传输数据:); for(int f =0;flength*8+len_d-1 ;f+) printf(%c,message_inputf); printf(n); printf(正在检错中.); printf(检错结果:); result = crc_function(message_input,len,dividend,len_d,RESULT,crc-len_d); for(int i = 0;i len_d-1;i+) if(*result = 1) printf(data error! n); break;
8、 else continue; result+=1; if(channel_way = TWO_ERROR) char *result = NULL; message_input0 = (message_input0 - 48)(1-48) + 48; message_inputlength*8-1 = (message_inputlength*8-1 - 48)(1-48) + 48; printf(信道中传输数据:); for(int f =0;flength*8+len_d-1 ;f+) printf(%c,message_inputf); printf(n); printf(正在检错中
9、.); printf(检错结果:); result = crc_function(message_input,len,dividend,len_d,RESULT,crc); for(int i = 0;i len_d-1;i+) if(*result != 0) printf( data error! n); break; else continue; result+=1; if(channel_way = RANDOM_ERROR) char *result = NULL; int no; srand( (unsigned)time( NULL ) ); .n); printf(检错结果:)
10、; result = crc_function(message_input,len,dividend,len_d,RESULT,crc); for(int i = 0;i len_d-1;i+) if(*result != 0) printf( data error! n); break; else continue; result+=1; printf(*n); printf(n); printf(n); else printf(Please select the parity moden); printf( parity n); printf( parityn); scanf(%d,&fl
11、ag_parity); char m = Parity_check(message_input,length*8,Parity); printf(在信道中传输的message:); message_inputlength*8 = m ; for(int message_number = 0;message_number=length*8;message_number+) printf(%c,message_inputmessage_number); printf(n); printf(*n); printf(* analog channel *n); printf(*please choice
12、 the way of error*n); printf(* error *n); printf(* error *n); printf(* errors *n); scanf(%d,&channel_way); if(channel_way = NO_ERROR) for(int f =0;flength*8;f+) printf(%c,message_inputf); printf(正在检错中.n); printf(检错结果:); char flag_parity_mode = Parity_check(message_input,length*8,check); if(flag_pari
13、ty_mode = (message_inputlength*8) printf(no error!n); if(channel_way = ONE_ERROR) message_input0 = (message_input0 - 48)(1-48) + 48; for(int f =0;flength*8;f+) printf(%c,message_inputf); printf(正在检错中.n); printf(检错结果:); char flag_parity_mode = Parity_check(message_input,length*8,check); printf( error
14、!n); if(channel_way = TWO_ERROR) message_input0 = (message_input0 - 48)(1-48) + 48; message_inputlength*8-1 = (message_inputlength*8-1 - 48)(1-48) + 48; for(int f =0;flength*8;f+) printf(%c,message_inputf); printf(正在检错中.n); printf(检错结果:); char flag_parity_mode = Parity_check(message_input,length*8,c
15、heck); printf(no error!n); printf(*n); printf(n); printf(n); fflush(stdin); printf(do you want to continuey/nn); scanf(%c,&flag); if(flag = y) continue; else break; /*/function: 完成字节转换成位的功能/输入字符:In 输出的二进制:Out*/void ByteToBit(char* out,const char* in,int bits) 中0=48 for(j=0;jlen;j+) /*把1传入 48表示为0;*/
16、if(*input_p=48) 入界面2.输入数据3. CRC校验1)No error2)One error3)Two errors4)Random errors4. 奇偶校验界面Even parity1)No error2)One error3)Two errorsOdd parity1)No error2)One error3)Two errors十、实验结论:奇偶校验,1位错可发现,2位错不可发现(奇数个错可发现,偶数个错不可发现)。而CRC校验,奇数或偶数个错均能发现。说明CRC校验比奇偶校验好的多。十一、总结及心得体会:通过本次实验,加深了C+的学习,虽然是结合网上的一些资料,但还是圆满完成,上次叫的作业写的不是很认真,望老师见谅,并且了解了CRC与奇偶校验的工作特性。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1