C ++中的任何前向纠错(FEC)实现 [英] Any forward error correction (FEC) implementation in C++

查看:294
本文介绍了C ++中的任何前向纠错(FEC)实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中是否有任何前向纠错(FEC)实现?我的项目需要它.我将字符转换为ascii值,然后将其转换为二进制值.现在,我需要附加纠错位.
我正在Visual Studio 2005中的vc ++中做我的项目.以下是我的代码的一部分:

Any forward error correction (FEC) implementation in C++? i need it for my project. i converted character into ascii value then converting them into binary values.now i need to append error correcting bits.
i m doing my project in vc++ in visual studio 2005. Following is part of my code:

array< array< int >^ >^ chartobin(array^arr,int length,int imgsize1)
{
//converts entered characters into binary n stores in message array
int ascii;
array< array< int >^ >^ messag= gcnew array< array< int >^ >(imgsize1);
  for(int i=0;i<imgsize1;i++)>
  {
     messag[i] = gcnew array(8);
  }
  for(int x= 0;x<length;x++)>
  {
    ascii =(int) arr[x];
    int* binary_reverse = new int [9];
    int* binary = new int [9];
    int y = 0;
    while(ascii != 1)
    {
      if(ascii % 2 == 0) //if ascii is divisible by 2
      {
        binary_reverse[y] = 0; //then put a zero
      }
      else if(ascii % 2 == 1) //if it isnt divisible by 2
      {
        binary_reverse[y] = 1; //then put a 1
      }
      ascii /= 2;
      y++;
    }
    if(ascii == 1) //when ascii is 1, we have to add 1 to the beginning
    {
      binary_reverse[y] = 1;
      y++;
    }
    if(y < 8) //add zeros to the end of string if not 8 characters (1 byte)
    {
      for(; y < 8; y++) //add until binary_reverse[7] (8th element)
      {
        binary_reverse[y] = 0;
      }
    }
    for(int z = 0; z < 8; z++) //our array is reversed. put the numbers in the rigth order (last comes first)
    {
      binary[z] = binary_reverse[7 - z];
      if(binary[z]==0)
      {
        binary[z]=-1;
      }
    }
    for(int z = 0; z < 8; z++)
    {
      messag[x][z]=binary[z];
    }
    delete [] binary_reverse; //free the memory created by dynamic mem. allocation
    delete [] binary;
  }
  return messag;
}


这里的length是我嵌入图像中的文本的长度.这就是为什么它必须比图像大小要小的原因. 现在,通过使messag [x] [z] = binary [z],我需要在消息中附加纠错位.像卷积编码器/维特比解码器这样的FEC.我迫切需要它.请帮助.

[edit]标记已更改,代码已重新格式化[/edit]


here length is the length of the text which i m embedding in the image.thats why it has to be lesser then the imagesize.
now by taking messag[x][z]=binary[z] i need to append error correcting bits in the message.the FEC like convolution encoder/Viterbi decoder. i need it urgently.pls help..

[edit]Tags changed, code re-formatted[/edit]

推荐答案

坦率地说,这很糟糕!
为什么有两个长度参数?如果长度"大于"imgsize1"会怎样?
您为什么要完全注释代码中的内容,而不是代码要实现的内容?任何阅读此内容的人都可以告诉:
That is, quite frankly, terrible!
Why have you got two length parameters? What happens if "length" is greater than "imgsize1"?
Why are you commenting exactly what the code says, instead of what the code is trying to achieve? Anyone who reads this can tell that:
if(ascii % 2 == 0)

表示

//if ascii is divisible by 2


为什么要先输出然后反转呢?为什么不一步一步做到呢?

为什么没有在单独的例程中转换字节的代码?

为什么要用这种方式?


Why are you outputting backwards and then reversing it? why not do it all in one step?

Why isn''t the code for converting a byte in a separate routine?

Why are you doing it this way?

if(ascii % 2 == 0) //if ascii is divisible by 2
        {
          binary_reverse[y] = 0; //then put a zero
        }
        else if(ascii % 2 == 1) //if it isnt divisible by 2
        {
          binary_reverse[y] = 1; //then put a 1
        }

为什么不

binary_reverse[y] = ascii % 2;


为什么不只有一个循环?


Why not just have one loop?

for(int i = 7; i >= 0; i--)
   {
   binary[i] = (ascii & 0x80) ? 1 : 0);
   ascii <<= 1;
   }


最重要的是,您要使用哪个FEC? Wiki-Forward_error_correction [


And on top of that, which FEC do you want to use?wiki - Forward_error_correction[^]

[edit]Oops - should have been "--" in the loop, not "++". Forgot to move the ascii bit, as well. I dunno, Sunday mornings...[/edit]


这篇关于C ++中的任何前向纠错(FEC)实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆