using namespace std;
#include <stdio.h>
class Transmitter
{
private:
unsigned int pay_load;
unsigned int parity;
unsigned int data_packet;
public:
Transmitter(unsigned int n)
{
pay_load = n;
}
void parity_bit()
{
unsigned int n = pay_load;
bool p = 0;
while (n)
{
p = !p;
n = n & (n - 1);
}
if(p == 1)
{
parity =1;
}
else{
parity =0;
}
cout<<"Parity is "<<parity<<endl;
}
int getpay_load()
{
return pay_load;
}
void dataPacket()
{
data_packet = (parity*32768) + (pay_load-32768);
cout<<"Data Packet is "<<data_packet<<endl;
}
};
class Reciever{
private:
unsigned int Rx_Pkt;
unsigned int Rx_Data;
unsigned int E_Flag;
void calculate_Eflag()
{
unsigned int n = Rx_Pkt;
bool p = 0;
while (n)
{
p = !p;
n = n & (n - 1);
}
if(p == 1)
{
E_Flag =1;
}
else{
E_Flag =0;
}
if(E_Flag == 0)
{
Rx_Data = Rx_Pkt;
}
else{
cout<<"The message is corrupted"<<endl;
}
}
};
class Tranciever: public Transmitter, public Reciever{
public:
};
int main()
{
unsigned int n;
cout<<"Enter a number : ";
cin>>n;
Transmitter t(n);
t.parity_bit();
t.dataPacket();
Reciever r;
}
Comments
Leave a comment