title: Which is the best way to check a bit array in Cuda?
body: <p>I need to launch N threads (in one block)</p>
  
  <p>This is the code, 'e' is a bignumber on 1024b. I need to copy it on the gpu and read it bit by bit. </p>
  
  <p>Host code:</p>
  
  <pre><code>unsigned char *__e;
  BIGNUM *e = BN_new();
  unsigned char exp[128];
  
  //      e
  i = cudaMalloc( (void**)&amp;__e, 128* sizeof(unsigned char) );
  if(i != cudaSuccess)
      printf("cudaMalloc __e FAIL! Code: %d\n", i);
  
  BN_bn2bin128B(e, exp);   // copy data in exp
  
  for(i=0; i&lt;128; i++)
      exp[i] = reverse(exp[i]);
  
  i = cudaMemcpy( __e, exp, 128* sizeof(unsigned char), cudaMemcpyHostToDevice);
  if(i != cudaSuccess)
      printf("cudaMemcpy __e FAIL! Code: %d\n", i);
  
  
  unsigned char reverse(unsigned char b) {
   b = (b &amp; 0xF0) &gt;&gt; 4 | (b &amp; 0x0F) &lt;&lt; 4;
   b = (b &amp; 0xCC) &gt;&gt; 2 | (b &amp; 0x33) &lt;&lt; 2;
   b = (b &amp; 0xAA) &gt;&gt; 1 | (b &amp; 0x55) &lt;&lt; 1;
   return b;
  }
  </code></pre>
  
  <p>Device code:</p>
  
  <pre><code>for(int i=0; i&lt;1024; i++)
      if(ISBITSET(__e, i) == 1)
          //do something
  </code></pre>
  
  <p>Header:</p>
  
  <pre><code>#define ISBITSET(x,i) ((x[i&gt;&gt;3] &amp; (1&lt;&lt;(i&amp;7)))!=0)
  </code></pre>
  
  <p>Unfortunately ISBITSET doesnt accept anything different from __e, so I cant check the further values in __e itself</p>
  
  <p>How can I solve it? Or is there a better way?</p>