C++ Program To Implement Manchester and Differential Manchester Encoding

Manchester and Differential Manchester Encoding

Here I have written a simple code in c++ which is an implementation of Manchester and Differential Manchester. In this encoding scheme, we need to draw a graph indicating Negative (below neutral Line) and Positive(above neutral line). So I have made an assumption as 0 as Postive and 1 as Negative initially.

While Running a program User is asked to enter the number of bits and once entered then ask to enter the bitstream one by one. It is Necessary to mention a previous bit so that it provides an output accordingly and then it enters a for loop. For Manchester, If it encounters a bit as "0" then it will trigger "01" and if it encounters a bit as "1" then triggers "10".

C++ Program To Implement Manchester & Differential Manchester

#include<iostream>
using namespace std;
int main()
{
int n,bit;
int bitstream[50];
cout<<"Assumption : 0 -> +ve and 1 -> -ve"<<endl;
cout<<"Enter the number of Bits : ";
cin>>n;
cout<<"Enter the Bitstream : ";
for(int i=0;i<n;i++)
    cin>>bitstream[i];
cout<<"Enter Previous Bit : ";
cin>>bit;
cout<<"Manchester Encoding : ";
for(int i=0;i<n;i++)
{
    if(bitstream[i] == 0)
        cout<<"01 ";
    if(bitstream[i] == 1)
        cout<<"10 ";
}
cout<<endl<<"Differential Manchester Encoding : ";
for(int i=0;i<n;i++)
{
    if(bitstream[i]==0)
        if(bit == 0)
        {   cout<<"10 "; bit=0;  }
        else
        {   cout<<"01 "; bit = 1; }
    else
        if(bit == 0)
        {   cout<<"01 "; bit = 1; }
        else
        {   cout<<"10 "; bit=0;  }
}
return 0;
}


OUTPUT :
Assumption : 0 -> +ve and 1 -> -ve
Enter the number of Bits : 9
Enter the Bitstream : 0 1 0 0 1 1 1 0 1
Enter Previous Bit : 0
Manchester Encoding : 01 10 01 01 10 10 10 01 10


Differential Manchester Encoding : 10 01 01 01 10 01 10 10 01


tags: Manchester Encoding, Differential Manchester Encoding,programming language, learn programming, computer networks, computer network,computer network coding.


Post a Comment

Previous Post Next Post