0% found this document useful (0 votes)
80 views16 pages

Data Communication Assignment - 181002013

The document describes an assignment for a data communication lab course. It includes 4 programming assignments involving binary data transmission techniques like checksum calculation, 2D parity checking, error detection using cyclic redundancy check, and character stuffing/de-stuffing. It provides code snippets and sample outputs for each assignment. The assignments aim to demonstrate concepts like error detection, correction, and secure data transmission.

Uploaded by

Abu Talha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views16 pages

Data Communication Assignment - 181002013

The document describes an assignment for a data communication lab course. It includes 4 programming assignments involving binary data transmission techniques like checksum calculation, 2D parity checking, error detection using cyclic redundancy check, and character stuffing/de-stuffing. It provides code snippets and sample outputs for each assignment. The assignments aim to demonstrate concepts like error detection, correction, and secure data transmission.

Uploaded by

Abu Talha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

GREEN UNIVERSITY OF BANGLADESH

Assignment

COURSE TITLE: Data Communication LAB


COURSE CODE: CSE 308

Date of performance : 09 – 04 – 2020


Date of submission : 02 – 06 – 2020

Submitted To
Mohammad Ehsan Shahmi Chowdhury
Lecturer
Department of CSE

Submitted By
Name: Mahmuda Akter
ID: 181002013
Section: 181_DD
Dept. : CSE
Assignment # 1(A):
#include<stdio.h>
#include<conio.h>
int add(int,int);
int com(int);

void checksum(int digi[],int n)


{

//checksum
int i,j,dl,dil;
int
data1[20],newdata[20]={},newdata1[20]={},comp[20],checksum[20],c
r[20]={};

printf("\nEnter The data length=");


scanf("%d",&dl);

printf("Enter the following data one by one: \n");


for(i=0;i<n;i++){
printf("%d",digi[i]);
if((i+1)%dl==0){
printf("\n");
}
}

for(j=1;j<=(n/dl);j++){

printf("\n Enter The Data %d : \n",j);


for(i=0; i<dl; i++)
scanf("%d",&data1[i]);

for(i=dl-1; i>=0; i--)


{
newdata[i]=add(data1[i],newdata[i]);
newdata1[i]=newdata[i];

}
for(i=dl-1; i>=0; i--)
{
newdata[i]=add(newdata1[i],cr[i]);
}
}

printf("\n\n New Data Is : ");


for(i=0; i<dl; i++)
{
printf("%d",newdata[i]);
}
printf("\n New Bit Stream Received From Sender : ");
printf("\n Checksum : ");
for(i=0; i<dl; i++)
{
checksum[i]=com(newdata[i]);
printf("%d",checksum[i]);
}

getch();
}
int main()
{
int n=7,k,i,j;
int roll[1000]={};

printf("Student ID using space:\n");


j=0;
do
{
scanf("%d",&n);
int a[10]= {};
for(i=0; n>0; i++)
{
a[i]=n%2;
n=n/2;
}
for(i=3; i>=0; i--)
{
roll[j]=a[i];
printf("%d",a[i]);
j++;
}
printf(" ");

}while(getchar()!='\n');

printf("\n\nDigital Bit Stream Number: ");


k=j;

for(i=0; i<k; i++)


{
printf("%d",roll[i]);
}
checksum(roll,k);
return 0;
}

int add(int x, int y)


{
int static carry=0;
if(x==1 && y==1 && carry==0)
{
carry=1;
return 0;
}
else if(x==1 && y==1 && carry==1)
{
carry=1;
return 1;
}
else if(x==1 && y==0 && carry==0)
{
carry=0;
return 1;
}
else if(x==1 && y==0 && carry==1)
{
carry=1;
return 0;
}
else if(x==0 && y==1 && carry==0)
{
carry=0;
return 1;
}
else if(x==0 && y==1 && carry==1)
{
carry=1;
return 0;
}
else if(x==0 && y==0 && carry==0)
{
carry=0;
return 0;
}
else
{
carry=0;
return 1;
}
}
int com(int a)
{
if(a==0)
return 1;
else
return 0;
}
Output:

Assignment # 1(B):
#include<stdio.h>
void TwoDprity(int digi[],int size)
{
int n,data[20][20],i,j,count=0;
printf("\n\nEnter the no. of Chanks: ");
scanf("%d",&n);
int s=(size/n);
int x=0;
for(i=0;i<n;i++){
for(j=0;j<s;j++){
data[i][j]=digi[x];
x++;
}
}
printf("Entered Date by Divide chanks Is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<s;j++)
printf("%d ",data[i][j]);
printf("\n");
}
//Row Parity checking
for(i=0;i<n;i++){
for(j=0;j<s;j++){
if(data[i][j]==1){
count++;
}
if(count%2==0) data[i][s]=1;
else data[i][s]=0;
}
count=0;
}
//Data with row parity
printf("Data with row parity:\n");
for(i=0;i<n;i++)
{
for(j=0;j<=s;j++)
printf("%d ",data[i][j]);
printf("\n");
}
//Column Parity checking
for(i=0;i<=s;i++){
for(j=0;j<n;j++){
if(data[j][i]==1){
count++;
printf("%d",count);
}
if(count%2==0) data[n][i]=1;
else data[n][i]=0;
}
count=0;
}
//Data with column parity
printf("Data with column parity:\n");
for(i=0;i<=n;i++)
{
for(j=0;j<=s;j++)
printf("%d ",data[i][j]);
printf("\n");
}

printf("Data with parity:\n");


for(i=0;i<=n;i++)
{
for(j=0;j<=s;j++)
printf("%d ",data[i][j]);
printf(" ");
}
}
int main()
{

int n=7,k,i,j;
int roll[1000]={};
printf("Student ID using space:\n");
j=0;
do
{
scanf("%d",&n);
int a[10]= {};
for(i=0; n>0; i++)
{
a[i]=n%2;
n=n/2;
}
for(i=3; i>=0; i--)
{
roll[j]=a[i];
printf("%d",a[i]);
j++;
}
printf(" ");

}while(getchar()!='\n');

printf("\n\nDigital Bit stream number: ");


k=j;

for(i=0; i<k; i++)


{
printf("%d",roll[i]);
}
TwoDprity(roll,k);
return 0;
}
Output:

Assignment # 02:
#include<stdio.h>
void division(int temp[],int gen[],int n,int r)
{
for(int i=0; i<n; i++)
{
if (gen[0]==temp[i])
{
for(int j=0,k=i; j<r+1; j++,k++)
if(!(temp[k]^gen[j]))
temp[k]=0;
else
temp[k]=1;
}
}
}
int main()
{
int n,r,message[50],gen[50],temp[50];

printf("Enter the number of message bits : ");


scanf("%d",&n);
printf("Enter the number of generator bits : ");
scanf("%d",&r);
printf("Enter the generator : ");
for(int i=0; i<r; i++)
scanf("%d",&gen[i]);
r--;

printf("\nAt Receiver's End ");


printf("\nEnter the received message : ");
for(int i=0; i<n+r; i++)
scanf("%d",&message[i]);
for(int i=0; i<n+r; i++)
temp[i] = message[i];
division(temp,gen,n,r);
for(int i=0; i<r; i++)
{
if(temp[n+i])
{
printf("\nError detected in received message.");
return 0;
}
}
printf("No error in received Message.\nReceived Message :
");
for(int i=0; i<n; i++)
printf("%d ",message[i]);
return 0;
}
Output:

Assignment # 03:
#include<stdio.h>
#include<string.h>
int main()
{
char j[50],i[50]="";
int x,y,k,len,c=0;
printf("Enter data in binary form : ");
scanf("%s",&j);
len=strlen(j);

for(x=6,y=0;x<len-6;x++,y++)
{
if(j[x]=='0')
{
c++;
if(c==3)
{
i[y]=j[x]; x=x+1; c=0;
}
else
{
i[y]=j[x];
}
}
else
{
c=0; i[y]=j[x]; }
}
i[y]='\0';
printf("\nAfter De-stuffing:%s",i);

}
Output:
Assignment # 04:
#include<stdio.h>
int main()
{
int i=0,c=0,x=0,j;
char data[80],receiver[500],arr[500], escape[50] =
"iknowright";

printf("Character Stuffing.\n\n**SENDER PART**\n\nEnter Sender


Data: ");
scanf("%s",data);
printf("\nAfter Character Stuffing, Encrypted data is: \n");
for(i=0; i<strlen(data); i++)
{

if(data[i]=='a'){
arr[x++]='a';
for(j=0;j<strlen(escape);j++){
arr[x++]=escape[j];

}
}
else{
arr[x++]=data[i];
}
}
printf("\n%s",arr);
x=0;

int len=strlen(arr);
printf("\n\n**RECEIVER PART**\n\n");
printf("\nAfter Character DE-Stuffing, Original data is: ");
for(i=0; i<len; i++)
{
if(arr[i]=='a'){
receiver[x++]='a';
i=i+strlen(escape);
}
else{
receiver[x++]=arr[i];
}
}
printf("\n%s",receiver);

return 0;
}

Output:

You might also like