So that's why you store it in your second array? My example was to show you how to touch each element in chunks of 8. To modify it, you would do:
Code:for(int i=0;i<sizeof(inputBuffer);i+=8){ for(int j=0; j<8; j++){ printf("%d\n", i+j); //whatever multiplication you want for //and store in second array } //whatever you want to do with the 8 elements //This section represents each chunk of 8 }
yes quzah, i actually have three for loops, (1) entire array (2) chunks of 8. (3) when it hits 7. thats not the problem. i dont think anyone gets the problem. you think i just need to go through the loop and convert all 0s and 1s to decimal, well thats not the case. here is my updated loop. that gets some characters right but not quite.
Code:int array01[34] = {0,1,0,0,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,1,7,0,0,1}; int word[10]; int d=128, j=0, m=0, k=0, n=0; for (j=0;j<(i-k);j++){ for (n=0;d!=1 && array01[m]!=7;n++){ word[p]+=array01[m]*d; m++; d=d/2;} printf("printing word - %d\n",word[p]); d=128; p++; m++; if (array_01[m-1]==7){ m++; for (n=0; n<8-p ;n++){ word[p+1]+=array_01[m]*d; m++; d=d/2;} printf("printing word - %d\n",word[p]); } } }
Last edited by vegan; 08-11-2011 at 08:31 PM.
So have you traced your logic when array is 7? You increment m, and then keep on reading from array01. If you don't want to do that, then don't do that. You don't have to do anything if you want the rest of the numbers to be 0, because adding 0 doesn't change anything.
Last edited by tabstop; 08-11-2011 at 08:32 PM. Reason: names
7 is just a number it doesnt mean chunks of 8. 7 could be 3 or 4 as long as it not 0 or 1. yep, the code exits the loop because the rest of numbers supposed to be 0 so im not adding them cos multiplication would be 0 anyway.
Last edited by vegan; 08-11-2011 at 08:35 PM.
We don't know what you are talking about because it is hard, at least for me, to follow the logic in your code. If you want to convert each binary number individually based on byte order, then convert the resultant 8 bit sections to a word look at the logic in the loop I posted above. You could fill in the areas I commented with your conversions and it will work.
thanks andrew and thank you all for trying))
suppose it is a long array and there are more than 7s. so say 01001 7 1010 7 01100 (i use spaces for clarity) supposed to be the same as 01001[000]1010[0000]01100[000] i.e. every time it hits 7 it should start multiplying by 128 not continuing where it stopped before 7.
off to bed.. thanks again you all)
It's usually a bad idea to just keep throwing more code at a problem -- especially since you don't seem to even understand your problem. I've got an idea, how about simply printing your array in groups of X?Once you have something simple working, then try to do more. Don't just keep slapping more loops on hoping it happens to work right. That hardly ever works.Code:for( x = 0; x < size of array; x += block size ) for( y = 0; y < block size; y++ ) do something with array[ x + y ]
Quzah.
Hope is the first step on the road to disappointment.