资源简介
使用C语言编写的曼彻斯特编码和解码功能函数
代码片段和文件信息
#include
#include
#include
const int size=10;
void Display()
{
cout<<“\nselect what you want to do:“< cout<<“0.Exit“;
cout<<“1.Manchester encoding.“< cout<<“2.Differential Manchester encoding.“< cout<<“3.Translate the Manchester code into original one.“< cout<<“4.Translate the Differential Manchester code into original one.“< }
/*void Encipher_M(char code[]) //Manchester Encoding
{
int ilen;
len=strlen(code);
cout<<“the Manchester code is: “;
for(i=0;i {
if(code[i]==‘1‘)
cout<<“10“;
else cout<<“01“;
}
cout< }
void Encipher_DM(char code[]) //Differential Manchester Encoding
{
int ilena[2*size];
len=strlen(code);
cout<<“the Differential Manchester code is: “;
if(code[0]==‘1‘)
{
a[0]=1; a[1]=0;
}
else {
a[0]=0; a[1]=1;
}
for(i=1;i {
if(code[i]==‘0‘)
if(a[2*i-1]==0){
a[2*i]=1; a[2*i+1]=0;
}
else{
a[2*i]=0; a[2*i+1]=1;
}
else
if(a[2*i-1]==0){
a[2*i]=0; a[2*i+1]=1;
}
else{
a[2*i]=1; a[2*i+1]=0;
};
}
for(i=0;i<2*len;i++)
cout< cout< }*/
void Decipher_M(char code[]) //translate the Manchester code to original one.
{
int ilena[size];
len=strlen(code);
while(len%2)
{
cout<<“the Manchester code input is wrong.please input again:“< cin>>code;
len=strlen(code);
}
while(len>size*2)
{
cout<<“the code input is beyond length limit.please input again:“< cin>>code;
len=strlen(code);
}
for(i=0;i {
if(code[i]==‘0‘&&code[i+1]==‘1‘)
{
a[i/2]=0;
}
else if(code[i]==‘1‘&&code[i+1]==‘0‘)
{
a[i/2]=1;
}
else
{
cout<<“the Manchester code input is wrongcan‘t translate into original code.“< return;//想在如果出现这个ELSE情况的时候就跳出FOR循环。。。。
}
}
for(i=0;i {
cout< }
cout< }
/*void Decipher_DM(char code[]) //translate Differential Manchester code into original one.
{
int ilena[size];
len=strlen(code);
while(len%2)
{
cout<<“the Differential Manchester code input is wrong.please input again:“< cin>>code;
len=strlen(code);
}
while(len>size*2)
{
cout<<“the code input is beyond length limit.please input again:“< cin>>code;
len=strlen(code);
}
if(code[0]==‘0‘&&code[1]==‘1‘) a[0]=0;
else if(code[0]==‘1‘&&code[1]==‘0‘) a[0]=1;
else cout<<“the code input is wrong.can‘t translate into original code.“< for(i=2;i {
if(code[i-1]==‘0‘)
if(code[i]==‘0‘&&code[i+1]==‘1‘) a[i/2]=1;
else if(code[i]==‘1‘&&code[i+1]==‘0‘) a[i/2]=0;
else cout<<“the code input is wrong.can‘t translate into original code.“< else if(code[i-1]==‘1‘)
if(code[i]==‘1‘&&code[i+1]==‘0‘) a[i/2]=1;
else if(code[i]==‘0‘&&code[i+1]==‘1‘) a[i/2]=0;
else cout<<“the code input is wrong.can‘t translat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-22 19:45 Manchester\Debug\
文件 3524 2017-10-22 17:25 Manchester\Manchester.cpp
文件 4332 2005-04-03 23:28 Manchester\Manchester.dsp
文件 543 2005-04-03 23:12 Manchester\Manchester.dsw
文件 41984 2005-04-05 22:20 Manchester\Manchester.ncb
文件 48640 2005-04-05 22:20 Manchester\Manchester.opt
文件 1296 2005-04-03 23:28 Manchester\Manchester.plg
目录 0 2005-04-05 22:20 Manchester\
- 上一篇:C++封装mp3文件转wav文件的DLL
- 下一篇:C语言LCD多级菜单(完整版)
评论
共有 条评论