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 1 ,0 ,0 },
142
- //orig { 1,0,1, 0,1,1,0, 1,1,1,0, 1,0,0,0, 0,1,0 },
143
- { 1 ,0 ,1 , 0 ,0 ,0 ,0 , 0 ,1 ,1 ,0 , 1 ,0 ,0 ,0 , 0 ,1 ,0 }, // CORRECTED
144
- { 1 ,0 ,1 , 0 ,1 ,1 ,0 , 1 ,1 ,1 ,0 , 1 ,0 ,0 ,0 , 0 ,1 ,0 },
145
- { 1 ,0 ,1 , 0 ,1 ,1 ,0 , 0 ,1 ,1 ,0 , 1 ,1 ,1 ,1 , 1 ,1 ,1 },
146
- { 1 ,1 ,0 , 0 ,1 ,0 ,1 , 0 ,1 ,0 ,0 , 0 ,0 ,0 ,1 , 1 ,1 ,0 },
147
- { 1 ,1 ,0 , 0 ,1 ,0 ,1 , 0 ,1 ,0 ,1 , 0 ,0 ,0 ,0 , 1 ,1 ,1 },
148
- };
149
83
150
84
void
151
85
read_p ()
@@ -581,16 +515,12 @@ int main()
581
515
generate_gf (); /* Construct the Galois Field GF(2**m) */
582
516
gen_poly (); /* Compute the generator polynomial of BCH code */
583
517
584
- #ifdef TEST
585
- for (int count = 0 ; count < sizeof (real_data ) / sizeof (* real_data ); count ++ ) {
586
- memcpy (data , real_data [count ], sizeof (* real_data ));
587
- #else
588
518
/* Randomly generate DATA */
589
519
seed = 131073 ;
590
520
srandom (seed );
591
521
for (i = 0 ; i < k ; i ++ )
592
522
data [i ] = ( random () & 65536 ) >> 16 ;
593
- #endif
523
+
594
524
encode_bch (); /* encode data */
595
525
596
526
/*
@@ -623,9 +553,8 @@ for (int count = 0; count < sizeof(real_data) / sizeof(*real_data); count++) {
623
553
printf ("r(x) = " );
624
554
for (i = 0 ; i < length ; i ++ ) {
625
555
printf ("%1d" , recd [i ]);
626
- if (i == length - k - 1 ) printf (" " );
627
- //if (i && ((i % 50) == 0))
628
- //printf("\n");
556
+ if (i && ((i % 50 ) == 0 ))
557
+ printf ("\n" );
629
558
}
630
559
printf ("\n" );
631
560
@@ -649,18 +578,6 @@ if (i == length - k - 1) printf(" ");
649
578
}
650
579
printf ("\n" );
651
580
652
- int flag = 0 ;
653
- printf ("n=%d, k=%d, length=%d\n" , n , k , length );
654
- #ifdef TEST
655
- for (int jj = 0 ; jj < n - k ; jj ++ ) {
656
- if (expected [count ][jj ] != recd [jj ]) {
657
- printf ("bit %d: expected %d calc: %d\n" , jj , expected [count ][jj ], recd [jj ]);
658
- flag ++ ;
659
- }
660
- }
661
- printf ("%d ERRORS.\n" , flag );
662
- #endif
663
-
664
581
/*
665
582
* DECODING ERRORS? we compare only the data portion
666
583
*/
@@ -671,7 +588,4 @@ printf("n=%d, k=%d, length=%d\n", n, k, length);
671
588
printf ("There were %d decoding errors in message positions\n" , decerror );
672
589
else
673
590
printf ("Succesful decoding\n" );
674
- #ifdef TEST
675
- }
676
- #endif
677
591
}
0 commit comments