home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,242 of 33,346   
   matt d to All   
   is using memcopy() to manipulate arrays    
   09 Oct 13 16:18:06   
   
   From: matt.doolittle33@googlemail.com   
      
   Hi everybody:   
   I am trying to use memcopy() to take certain bits out of one array   
   (encoded_lcw), put them into another array (edata), processes that   
   array, and finally put the edata array into third array (rs_codewords).   
   here is the code:   
      
   uint16_t   
   decode_hamming(uint16_t encoded_lcw)   
   {   
       //uint16_t * rs_codewords[144]; //should a 144 bit array for the rs decode   
       uint16_t edata[10];   
       for (int index = 0; index < 24; index++)   
       {   
           //  get 24 10-bit codewords out of 240 bit aencoded_lcw array   
           //  and put the 10 bit arrays in edata[]   
           memcpy(edata, (encoded_lcw+10*index), 10);   
      
           int encoded[11],syndrome[4];   
           int hmatrix[4][10] =	//parity matrix   
                           {   
       					1, 1, 1, 0, 0, 1, 1, 0, 0, 0,   
                           1, 1, 0, 1, 0, 1, 0, 1, 0, 0,   
                           1, 0, 1, 1, 1, 0, 0, 0, 1, 0,   
                           0, 1, 1, 1, 1, 0, 0, 0, 0, 1   
       					};   
      
           int i;   
           int j;   
       	for(i=0;i<4;i++)   
       	{   
       		for(j=0;j<10;j++)   
       		syndrome[i]+=(edata[j]*hmatrix[i][j]);   
       		syndrome[i]=syndrome[i]%2;   
       	}   
       	for(j=0;j<10;j++)   
       	if((syndrome[0]==hmatrix[0][j]) && (syndrome[1]==hmatrix[1][j])&&   
   	   (syndrome[2]==hmatrix[2][j]) && (syndrome[3]==hmatrix[3][j]))   
       	break;   
       	if(j==10)   
       	printf("\nError free\n");   
       	else   
       	{   
       		//printf("\nError recieved at bit number %d of data\n",j+1);   
       		edata[j]=!edata[j];   
       		//printf("\nCorrect data should be : ");   
       		for(i=0;i<10;i++)   
       			printf("%d",edata[i]);   
                   //edata[i] is the corrected ten bit codeword   
                   //have to remove the last 4 parity bits to get the original 6   
   bit data or hex bits   
                   //then put the 24 hex bits into an array for the reed-solomon   
   decoder below   
       	}   
            // put all 24 edata[] 6-bit arrays into one array   
            // truncated to remove parity bits   
           memcpy((rs_codewords+index*6), edata, 6);   
      
       }   
       return rs_codewords;   
   }   
      
      
   First i am getting a whole lot of trouble at complile time:   
      
   lcw_ecc.h: In function ‘uint16_t lcw_ecc(uint16_t)’:   
   lcw_ecc.h:21:37: error: invalid conversion from ‘uint16_t* {aka short unsigned   
   int*}’ to ‘uint16_t {aka short unsigned int}’ [-fpermissive]   
   lcw_ecc.h:15:10: error:   initializing argument 1 of ‘uint16_t d   
   code_reed_solomon(uint16_t)’ [-fpermissive]   
   lcw_ecc.h:22:12: error: invalid conversion from ‘uint16_t* {aka short unsigned   
   int*}’ to ‘uint16_t {aka short unsigned int}’ [-fpermissive]   
   lcw_ecc.h: In function ‘uint16_t decode_hamming(uint16_t)’:   
   lcw_ecc.h:34:49: error: invalid conversion from ‘int’ to ‘const void*’   
   [-fpermissive]   
   In file included from lcw_ecc.h:9:0:   
   /usr/include/string.h:44:14: error:   initializing argument 2 of ‘void*   
   memcpy(void*, const void*, size_t)’ [-fpermissive]   
   lcw_ecc.h:76:12: error: invalid conversion from ‘uint16_t* {aka short unsigned   
   int*}’ to ‘uint16_t {aka short unsigned int}’ [-fpermissive]   
      
   Second I am not sure using memcopy() for this task is the appropriate   
   (ie. most efficient approach this side of using bitwise operations)   
   approach to solving the task of manipulating these arrays, although at   
   it sure seems like less work for me. If there is a different way that   
   i should be solving me problem I would love to know.   
      
   i am using g++ to compile in terminal on Ubuntu.  I have looked in my c++   
   book and i have Googled the issue.  Any help will be much appreciated.   
      
   ATB   
   Matt   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca