c - print elements of one array based on values set in another array -


i have 2 arrays, 1 data[n] array of type int , stores random values. other result[n/4] array, has details 4 integers of 'data' array in 1 element.

for example : result[0]=1000 0000 1000 0000 0000 0000 1000 0000 implies data[0], data[1], data[3] needed printed out. simillarly result[1] has details data[4] data[7] in each byte of , hence if 'n' elements present in data array, n/4 elements present in result array.

now provided result , data arrays , count value(no. of elements in result array) , have print 'data' values 'result' value set(i.e., '1000 0000'). have tried 2 methods.

method 1:

i=0;j=0; while(i<count)  { if((result[i]>>24 & 0xff) > 0) printf("%d",data[j]); if((result[i]>>16 & 0xff) > 0) printf("%d",data[j+1]); if((result[i]>>8 & 0xff) > 0) printf("%d",data[j+2]); if((result[i]>>0 & 0xff) > 0) printf("%d",data[j+3]); i++; j+=4; } 

method 2 :

while(i<count){     if((res[i] & 0x80000000)==0x80000000)  printf("%d\n",dat[x]);      if((res[i] & 0x00800000)==0x00800000)  printf("%d\n",dat[x+1]);      if((res[i] & 0x00008000)==0x80008000)  printf("%d\n",dat[x+2]);      if((res[i] & 0x80000080)==0x80000080)  printf("%d\n",dat[x+3]);      i++;     x+=4; } 

i not satisfied performance of first method eliminated shift operator code , went second one. there considerable improvement in speed, improved speed not enough application. suggest other techniques solve problem in faster way of stated 2 methods.

your bottle neck printf() function call - build new string first , print after doing checks - 1 printf() call per 4 byte check improvement. can reduce printf() calls more printing if @ end of result or every full line (console window).

hope helps, - neil


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -