aboutsummaryrefslogtreecommitdiff
path: root/q3
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-16 10:35:10 +0000
committerAkshay <[email protected]>2020-12-16 10:35:10 +0000
commite8186e657d51d9deedd171981d314933ed408db5 (patch)
tree786837fcbd271abf21443652986888ba6120ca63 /q3
parenta33f3a8a5a392ae7bcc8187216cff8583b7518ac (diff)
add q3, q2, images
Diffstat (limited to 'q3')
-rw-r--r--q3/checksum.c37
-rwxr-xr-xq3/checksum.obin0 -> 18600 bytes
-rw-r--r--q3/hamming.c56
-rwxr-xr-xq3/hamming.obin0 -> 18568 bytes
4 files changed, 93 insertions, 0 deletions
diff --git a/q3/checksum.c b/q3/checksum.c
new file mode 100644
index 0000000..513ae17
--- /dev/null
+++ b/q3/checksum.c
@@ -0,0 +1,37 @@
1#include <stdio.h>
2#include <stdio.h>
3
4int checksum() {
5 unsigned int parts[9];
6 unsigned int sum;
7 printf("Enter the parts, one per line:\n");
8 for (int i = 0; i < 9; i++) {
9 scanf("%X", &parts[i]);
10 sum += parts[i];
11 while (sum >> 16)
12 sum = (sum & 0xffff) + (sum >> 16);
13 }
14 return ~sum;
15}
16
17int main() {
18 printf("--- SENDER ---\n");
19 int sender_checksum = checksum();
20 printf("\n--- RECV ---\n");
21 int recv_checksum = checksum();
22 printf("Sent checksum: %x\n", sender_checksum);
23 printf("Recieved checksum: %x\n", recv_checksum);
24 if (sender_checksum == recv_checksum) {
25 printf("Matching checksums!\n");
26 return 0;
27 } else {
28 printf("Mismatched checksums!\n");
29 return 0;
30 }
31}
32
33// 00004500 00000073 00000000 00004000 00004011 0000c0a8 00000001 0000c0a8 000000c7
34// checksum - ffffb861
35
36// 00004500 0000003c 00001c46 00004000 00004006 0000ac10 00000a63 0000ac10 00000a0c
37// checksum - 0000b1e6
diff --git a/q3/checksum.o b/q3/checksum.o
new file mode 100755
index 0000000..cfcaed6
--- /dev/null
+++ b/q3/checksum.o
Binary files differ
diff --git a/q3/hamming.c b/q3/hamming.c
new file mode 100644
index 0000000..01d0f0e
--- /dev/null
+++ b/q3/hamming.c
@@ -0,0 +1,56 @@
1#include<stdio.h>
2
3void main() {
4 int data[10];
5 int dataatrec[10],c,c1,c2,c3,i;
6
7 printf("Sender: ");
8 scanf("%d %d %d %d",&data[0] ,&data[1] ,&data[2] ,&data[4]);
9
10 //Calculation of even parity
11 data[6]=data[0]^data[2]^data[4];
12 data[5]=data[0]^data[1]^data[4];
13 data[3]=data[0]^data[1]^data[2];
14
15 printf("Encoded Data: ");
16 for(i=0;i<7;i++)
17 printf("%d",data[i]);
18
19 printf("\nReceiver: ");
20 for(i=0;i<7;i++)
21 scanf("%d",&dataatrec[i]);
22
23 c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
24 c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
25 c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
26 c=c3*4+c2*2+c1 ;
27
28 printf("\nSyndrome bits: %d %d %d", c1, c2, c3);
29
30 if(c==0) {
31 printf("\nNo error while transmission of data\n");
32 }
33 else {
34 printf("\nError Position: %d",c);
35
36 printf("\nData sent: ");
37 for(i=0;i<7;i++)
38 printf("%d",data[i]);
39
40 printf("\nData received: ");
41 for(i=0;i<7;i++)
42 printf("%d",dataatrec[i]);
43
44 printf("\nCorrect message is: ");
45
46 //if errorneous bit is 0 we complement it else vice versa
47 if(dataatrec[7-c]==0)
48 dataatrec[7-c]=1;
49 else
50 dataatrec[7-c]=0;
51
52 for (i=0;i<7;i++) {
53 printf("%d",dataatrec[i]);
54 }
55 }
56}
diff --git a/q3/hamming.o b/q3/hamming.o
new file mode 100755
index 0000000..fa9cb70
--- /dev/null
+++ b/q3/hamming.o
Binary files differ