prototype
Dependents: Mbed_Prototype_copy_4_INNO_day_15_6_2017
Diff: crc.cpp
- Revision:
- 3:1250751bf7b0
- Parent:
- 2:c0d73ae91788
diff -r c0d73ae91788 -r 1250751bf7b0 crc.cpp --- a/crc.cpp Tue Jun 13 03:32:52 2017 +0000 +++ b/crc.cpp Tue Jun 20 05:34:42 2017 +0000 @@ -21,24 +21,24 @@ output.printf(" - "); } //output.printf("%d",sizeof(f)); - output.printf("\n The data to be analyzed is : "); + // output.printf("\n The data to be analyzed is : "); int frame[v+16]; for(h1=0; h1<v; h1++) { //storing the binary data in frame array - output.printf("%d",binary1[h1]); + // output.printf("%d",binary1[h1]); frame[h1]=binary1[h1]; } //frame[2]=0; - output.printf("\n The value of v is : %d ",v); //Printing the value of V i.e total binary no. + /* output.printf("\n The value of v is : %d ",v); //Printing the value of V i.e total binary no. output.printf("\n Sender Side:"); - output.printf("\n Frame: "); - for(i1=0; i1<v; i1++) { // total binary stream printing + output.printf("\n Frame: ");*/ + /* for(i1=0; i1<v; i1++) { // total binary stream printing output.printf("%d",frame[i1]); } - output.printf("\n Generator : "); // generator for CRC checking - for(i1=0; i1<16; i1++) { + output.printf("\n Generator : "); */ // generator for CRC checking + /* for(i1=0; i1<16; i1++) { output.printf("%d",generator[i1]); - } + }*/ //Append 0's int rs1=16-1; @@ -51,10 +51,10 @@ temp2[i1]=frame[i1]; } - output.printf("\n Message after appending 0's :"); + /* output.printf("\n Message after appending 0's :"); for(i1=0; i1<v+rs1; i1++) { //printing the data after appending zeros output.printf("%d",temp2[i1]); - } + }*/ //Division for(i1=0; i1<v; i1++) { //CRC generating through division operation @@ -78,12 +78,12 @@ crc[i1]=temp2[j1]; } - output.printf("\n CRC bits: "); + /*output.printf("\n CRC bits: "); for(i1=0; i1<rs1; i1++) { //printing CRC bits output.printf("%d",crc[i1]); - } + }*/ - output.printf("\n Transmitted Frame: "); + //output.printf("\n Transmitted Frame: "); int tf2[v+16]; char tf3[v+16]; for(i1=0; i1<v; i1++) { // copying the data from one to another @@ -92,24 +92,36 @@ for(i1=v,j1=0; i1<v+rs1; i1++,j1++) { // Adding CRC bits to the data tf2[i1]=crc[j1]; } - for(i1=0; i1<v+rs1; i1++) { // printing the data after adding the CRC bits to the data + /* for(i1=0; i1<v+rs1; i1++) { // printing the data after adding the CRC bits to the data output.printf("%d",tf2[i1]); - } + }*/ tf2[v+rs1]=0; + /* output.printf("\n The final data to be sent is : "); // printing the Final data + for(i1=0; i1<=v+rs1; i1++) { + output.printf("%d",tf2[i1]); + }*/ + + /* for(i1=0;i1<7;i1++) + { + tf2[i1]=1; + } + for(i1=136;i1<144;i1++) + { + tf2[i1]=1; + } output.printf("\n The final data to be sent is : "); // printing the Final data for(i1=0; i1<=v+rs1; i1++) { output.printf("%d",tf2[i1]); - } - + }*/ for(i1=0; i1<=v+rs1; i1++) { charBinary(tf2[i1]); } - output.printf("\n The final data to be sent is : "); + /* output.printf("\n The final data to be sent is : "); for(i1=0; i1<=v+rs1; i1++) { output.printf("%c",binary2[i1]); - } + }*/ printChar(binary2); char* str=result1; @@ -126,79 +138,41 @@ int i,j,k,l; int rs=15; v=0; - output.printf("\n Receiver side : "); - output.printf("\n Received Frame: "); + /* output.printf("\n Receiver side : "); + output.printf("\n Received Frame: ");*/ for(int m=0; m<18; m++) { printBinary(a1[m]); output.printf("-"); } - for(i=0; i<v; i++) { + /*for(i=0; i<v; i++) { output.printf("%d",binary1[i]); - } + }*/ v=v-16; int tf[v+16]; for(i=0; i<v+rs; i++) { tf[i]=binary1[i]; } - output.printf("\n"); - output.printf("The data to be Analyzed on the receiving side : "); - for(i=0; i<v+rs; i++) { + /*output.printf("\n"); + output.printf("The data to be Analyzed on the receiving side : ");*/ + /* for(i=0; i<v+rs; i++) { output.printf("%d",tf[i]); - } + }*/ int temp[v+16]; int temp3[v+16]; for(i=0; i<v+rs; i++) { temp[i]=tf[i]; - temp3[i]=tf[i]; + //temp3[i]=tf[i]; } - //changing data - - /*for(i=0; i<20; i++) { - if(i%2==0) { - tamp3[i]==0; - } - else - tamp3[i]==1; - - } - - - - for(i=20;i<143;i++) - { - temp3[i]=temp[i]; - } - for(i=0=i<sizeof(temp3);i++) - { - output.printf("after 20 wrong bits added in the binary data %d",binary1[i]); - } -*/ - - - /*//Division - for(i=0; i<v+rs; i++) { + + //Division + for(i=0; i<v; i++) { j=0; k=i; if (temp[k]>=generator[j]) { for(j=0,k=i; j<16; j++,k++) { - if((temp[k]==1 && generator[j]==1) || (temp[k]==0 && generator[j]==0)) { - temp[k]=0; - } else { - temp[k]=1; - } - } - } - }*/ - - //Division - for(i=0; i<v+rs; i++) { - j=0; - k=i; - if (temp[k]>=generator[j]) { - for(j=0,k=i; j<16; j++,k++) { - if((temp[k]==1 && generator[j]==1) || (temp[k]==0 && generator[j]==0)) { + if(temp[k] == generator[j]) { temp[k]=0; } else { temp[k]=1; @@ -207,7 +181,7 @@ } } - output.printf("\n Reaminder: "); + output.printf("\n Reaminder: "); int rrem[16]; for (i=v,j=0; i<v+rs; i++,j++) { rrem[j]= temp[i]; @@ -220,6 +194,7 @@ for(i=0; i<rs; i++) { if(rrem[i]!=0) { flag=1; + break; } }