-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathber.c
47 lines (40 loc) · 941 Bytes
/
ber.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAXBLOCKSIZE 65536
int main(int argc, char **argv)
{
int len1,len2,i,diff=0;
unsigned char buf1[MAXBLOCKSIZE],buf2[MAXBLOCKSIZE];
FILE *file1,*file2;
if (argc<3) {
printf("Usage: %s file1 file2 [-d]\n",argv[0]);
exit(1);
}
float errors=0,count=0;
file1=fopen(argv[1],"r");
file2=fopen(argv[2],"r");
if (argc==4)
if (strcmp(argv[3],"-d")==0)
diff=1;//activate diff mode
if (strstr(argv[0],"ber"))
{ // ber of bits
int b;
while((len1=fread(buf1,1,MAXBLOCKSIZE,file1))>0) {
len2=fread(buf2,1,MAXBLOCKSIZE,file2);
if (len2<len1) len1=len2;
for (i=0;i<len1;i++) {
count++;
for (b=0;b<8;b++)
if ((buf1[i] & (1<<b)) != (buf2[i] & (1<<b))) {
errors++;
if (diff) putc('@',stdout);
}
else if (diff) putc('.',stdout);
}
}
printf("%f (%.0f/%.0f)\n",(float)errors/(count*8.0),errors,count*8);
}
return 0;
}