-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.Check_Sum.c
More file actions
61 lines (56 loc) · 1.6 KB
/
5.Check_Sum.c
File metadata and controls
61 lines (56 loc) · 1.6 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c[8];
int i, j, f[4][8], sum[8], carry = 0, temp;
for( i = 0; i < 4; ++i )
{
printf("Enter the Data Frame %d:\n", i+1);
scanf("%s",c);
for( j = 0; j < 8; ++j )
f[i][j] = c[j]-48;
}
for( i = 7; i >= 0; --i )
{
temp = f[0][i] + f[1][i] + f[2][i] + carry;
sum[i] = temp%2;
if( carry ) carry = 0;
carry = temp/2;
}
for( i = 0; i < 8; ++i )
{
temp = sum[i]^f[3][i];
if( temp == 0 )
{
printf("There is an Error in Received Data Frames.");
exit(1);
}
}
printf("There is NO Error in Received Data Frames.");
return 0;
}
// Input/Output:-
// ------------
// Case 1:
// -------
// Enter the Data Frame 1:
// 10101001 /* Input */
// Enter the Data Frame 2:
// 00111001 /* Input */
// Enter the Data Frame 3:
// 00011101 /* Input */
// Enter the Data Frame 4:
// 00000000 /* Input */
// There is NO Error in Received Data Frames.
// Case 2:
// -------
// Enter the Data Frame 1:
// 10101001 /* Input */
// Enter the Data Frame 2:
// 00111001 /* Input */
// Enter the Data Frame 3:
// 00011100 /* Input */
// Enter the Data Frame 4:
// 00000000 /* Input */
// There is an Error in Received Data Frames.