From e8186e657d51d9deedd171981d314933ed408db5 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 16 Dec 2020 16:05:10 +0530 Subject: add q3, q2, images --- q3/checksum.c | 37 +++++++++++++++++++++++++++++++++++++ q3/checksum.o | Bin 0 -> 18600 bytes q3/hamming.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ q3/hamming.o | Bin 0 -> 18568 bytes 4 files changed, 93 insertions(+) create mode 100644 q3/checksum.c create mode 100755 q3/checksum.o create mode 100644 q3/hamming.c create mode 100755 q3/hamming.o (limited to 'q3') 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 @@ +#include +#include + +int checksum() { + unsigned int parts[9]; + unsigned int sum; + printf("Enter the parts, one per line:\n"); + for (int i = 0; i < 9; i++) { + scanf("%X", &parts[i]); + sum += parts[i]; + while (sum >> 16) + sum = (sum & 0xffff) + (sum >> 16); + } + return ~sum; +} + +int main() { + printf("--- SENDER ---\n"); + int sender_checksum = checksum(); + printf("\n--- RECV ---\n"); + int recv_checksum = checksum(); + printf("Sent checksum: %x\n", sender_checksum); + printf("Recieved checksum: %x\n", recv_checksum); + if (sender_checksum == recv_checksum) { + printf("Matching checksums!\n"); + return 0; + } else { + printf("Mismatched checksums!\n"); + return 0; + } +} + +// 00004500 00000073 00000000 00004000 00004011 0000c0a8 00000001 0000c0a8 000000c7 +// checksum - ffffb861 + +// 00004500 0000003c 00001c46 00004000 00004006 0000ac10 00000a63 0000ac10 00000a0c +// checksum - 0000b1e6 diff --git a/q3/checksum.o b/q3/checksum.o new file mode 100755 index 0000000..cfcaed6 Binary files /dev/null and b/q3/checksum.o 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 @@ +#include + +void main() { + int data[10]; + int dataatrec[10],c,c1,c2,c3,i; + + printf("Sender: "); + scanf("%d %d %d %d",&data[0] ,&data[1] ,&data[2] ,&data[4]); + + //Calculation of even parity + data[6]=data[0]^data[2]^data[4]; + data[5]=data[0]^data[1]^data[4]; + data[3]=data[0]^data[1]^data[2]; + + printf("Encoded Data: "); + for(i=0;i<7;i++) + printf("%d",data[i]); + + printf("\nReceiver: "); + for(i=0;i<7;i++) + scanf("%d",&dataatrec[i]); + + c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0]; + c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0]; + c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0]; + c=c3*4+c2*2+c1 ; + + printf("\nSyndrome bits: %d %d %d", c1, c2, c3); + + if(c==0) { + printf("\nNo error while transmission of data\n"); + } + else { + printf("\nError Position: %d",c); + + printf("\nData sent: "); + for(i=0;i<7;i++) + printf("%d",data[i]); + + printf("\nData received: "); + for(i=0;i<7;i++) + printf("%d",dataatrec[i]); + + printf("\nCorrect message is: "); + + //if errorneous bit is 0 we complement it else vice versa + if(dataatrec[7-c]==0) + dataatrec[7-c]=1; + else + dataatrec[7-c]=0; + + for (i=0;i<7;i++) { + printf("%d",dataatrec[i]); + } + } +} diff --git a/q3/hamming.o b/q3/hamming.o new file mode 100755 index 0000000..fa9cb70 Binary files /dev/null and b/q3/hamming.o differ -- cgit v1.2.3