C get bit / set bit consolidation
<p>I have this time critical code:</p>

<pre><code>#define READBIT(A, B) ((A &gt;&gt; (B &amp; 7)) &amp; 1)
#define SETBIT(T, B, V) (T = V ? T | (1&lt;&lt;B) : T &amp; ~(1&lt;&lt;B))

for (int j = 0; j &lt; 32; j++) {
  bits = 0;
  sc   = seckey[31 - j];
  SETBIT(bits, 0, READBIT(sc, 0));
  SETBIT(bits, 1, READBIT(sc, 1));
  SETBIT(bits, 2, READBIT(sc, 2));
  SETBIT(bits, 3, READBIT(sc, 3));
  SETBIT(bits, 4, READBIT(sc, 4));
  SETBIT(bits, 5, READBIT(sc, 5));
  SETBIT(bits, 6, READBIT(sc, 6));
  SETBIT(bits, 7, READBIT(sc, 7));

  &lt;do something with bits&gt;
}
</code></pre>

<p>My question is, if it is possible to transform the READBIT/SETBIT macros further - possibly consolidating them into one macro and lowering computational effort.</p>

<p>If I expand these macros (leaving B as a variable), I get (hopefully correct):</p>

<pre><code>bits = ((sc &gt;&gt; (B &amp; 7)) &amp; 1) ? bits | (1&lt;&lt;B) : bits &amp; ~(1&lt;&lt;B)
</code></pre>

<p>Where B can take values 0-7. Am I missing a simpler equivalent logical operation?</p>