Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

EXPERIMENT NO.

6
 
AIM: Write a program to translate dotted decimal ip address into 32 bit binary number.
 
PROGRAM:
 
# include<iostream.h>
# include<stdio.h>
# include<conio.h>
void main()
{             
clrscr();
int intial[4],final[8],n,a;
cout<<"Enter the ip address";
cin>>intial[0]>>intial[1]>>intial[2]>>intial[3];
cout<<"ip address"<<intial[0]<<"."<<intial[1]<<"."
    <<intial[2]<<"."<<intial[3];
cout<<"\nip address";
for(int i=0;i<=3;i++)
              {n=intial[i];
              for(int j=0;j<=7;j++)
 
                                    {
                                    a=n%2;
                                    n=n/2;
                                    final[j]=a ;
                                      }
              cout<<final[7]<<final[6]<<final[5]<<final[4]
            <<final[3]<<final[2]<<final[1]<<final[0];
              cout<<".";
              }
getch();
}
 
 
 
 
 
 
 
 
 
 
 
 
 
EXPERIMENT NO. 7
 
AIM: Write a program to calculate the Hamming code for a data word and check the received
codeword for erors.
 
PROGRAM:
 
#include<iostream.h>
#include<conio.h>
void main()
{
int a[4],r[3],s[3],b[4],q[3];
clrscr();
cout<<"Enter a four bit data word";
cin>>a[3]>>a[2]>>a[1]>>a[0];
r[0]=(a[2]+a[1]+a[0])%2;
r[1]=(a[3]+a[2]+a[1])%2;
r[2]=(a[0]+a[3]+a[2])%2;
cout<<"\nCodeword is"<<a[3]<<a[2]<<a[1]<<a[0]<<r[2]<<r[1]<<r[0];
cout<<"\nInput another codeword";
cin>>b[3]>>b[2]>>b[1]>>b[0]>>q[2]>>q[1]>>q[0];
s[0]=(q[0]+b[2]+b[1]+b[0])%2;
s[1]=(q[1]+b[3]+b[2]+b[1])%2;
s[2]=(q[2]+b[0]+b[3]+b[2])%2;
cout<<"\nSyndrome is"<<s[2]<<s[1]<<s[0];
if(s[2]==0)
              {if(s[1]==0)
                         {if(s[0]==0)
                         cout<<"No error";
                         else
                         cout<<"Error in q[0]";
                         }
              else
                         {if(s[0]==0)
                         cout<<"Error in q[1]";
                         else
                         cout<<"Error in b[2]";
                         }
              }
else
              {if(s[1]==0)
                         {if(s[0]==0)
                         cout<<"Error in q[2]";
                         else
                         cout<<"Error in b[0]";
                         }
              else
                         {if(s[0]==0)
                         cout<<"Error in b[3]";
                         else
                         cout<<"Error in b[1]";
                         }
              }
getch();
}
 

You might also like