-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParity Bit Generator.c
More file actions
90 lines (73 loc) · 1.57 KB
/
Copy pathParity Bit Generator.c
File metadata and controls
90 lines (73 loc) · 1.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//Parity Bit Generator
#include<stdio.h>
int main()
{
int n,bin=0,place=1,count=0;
printf("Enter the decimal number:\n");
scanf("%d",&n);
int temp=n;
while(n>0)
{
int digit=n%2;
bin+=(digit*place);
n/=2;
place=place*10;
}
printf("Binary number : %d\n",bin);
while(temp>0)
{
if(temp&1)
count++;
temp=temp>>1;
}
printf("Number of ones: %d",count);
int ch,output;
int recived;
printf("Enter the choice:\n");
printf("1-Even Parity\n2-Odd Parity\n");
scanf("%d",&ch);
switch(ch)
{
case 1: if(count%2==0)
{
output = bin*10+0;
printf("Parity bit generated is 0\n");
printf("Output: %d",output);
}
else
{
output=bin*10+1;
printf("\nParity bit generated is 1\n");
printf("Output: %d",output);
}
printf("\nEnter the reciver data:\n");
scanf("%d",&recived);
if(recived==bin)
printf("No error in Data\n");
else
printf("Error in Data\n");
return 0;
case 2: if(count%2!=0)
{
output = bin*10+1;
printf("Parity bit generated is 1\n");
printf("Output: %d",output);
}
else
{
output=bin*10+0;
printf("\nParity bit generated is 0\n");
printf("Output: %d",output);
}
printf("\nEnter the reciver data:\n");
scanf("%d",&recived);
if(recived==bin)
printf("No error in Data\n");
else
printf("Error in Data\n");
return 0;
default: printf("Invalid Choice\n");
break;
}
return 0;
}