#include #define MAX_ERRORS 10 int count_bits(unsigned char a){ int i,bits=0; for(i=0; i<8; i++){ if( ((a>>i) & 0x01) != 0) bits++; } return bits; } int main(int argc,char *argv[]){ if(argc != 3){ printf("Usage: %s \n",argv[0]); return -1; } long int total_bits = 0; long int total_errors = 0; int diff; unsigned char byte1, byte2; FILE* f1 = fopen(argv[1], "r"); FILE* f2 = fopen(argv[2], "r"); while((fread(&byte1, 1, 1, f1)) != 0){ if(fread(&byte2, 1, 1, f2) == 0) break; total_bits += 8; if(byte1 == byte2) continue; diff = count_bits(byte1 ^ byte2); total_errors += diff; if(total_errors < MAX_ERRORS){ printf("%d error[s] in byte %d.\n", diff, total_bits/8); } else if(total_errors==MAX_ERRORS){ printf("too many errors, no longer outputting location...\n"); } } fclose(f1); fclose(f2); printf("Total Bits: %lu\n", total_bits); printf("Total Errors: %lu\n", total_errors); double error_rate = (((double) total_errors) / ((double) total_bits)); printf("BER: %f\n", error_rate); }