Click here to Skip to main content
15,887,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}

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]
Posted
Updated 11-Apr-10 4:52am
v3

1 solution

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)
means
//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
        }
Why not
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;
   }

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]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900