Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code is cribbed directly from <a href="http://books.google.com/books?id=iBNKMspIlqEC&amp;lpg=SL20-PA11&amp;vq=Transposing%20an%208x8-bit%20matrix&amp;pg=SL20-PA11#v=snippet&amp;q=Transposing%20an%208x8-bit%20matrix&amp;f=false" rel="noreferrer">"Hacker's Delight" - Figure 7-2 Transposing an 8x8-bit matrix</a>, I take no credit for it:</p> <pre><code>void transpose8(unsigned char A[8], int m, int n, unsigned char B[8]) { unsigned x, y, t; // Load the array and pack it into x and y. x = (A[0]&lt;&lt;24) | (A[m]&lt;&lt;16) | (A[2*m]&lt;&lt;8) | A[3*m]; y = (A[4*m]&lt;&lt;24) | (A[5*m]&lt;&lt;16) | (A[6*m]&lt;&lt;8) | A[7*m]; t = (x ^ (x &gt;&gt; 7)) &amp; 0x00AA00AA; x = x ^ t ^ (t &lt;&lt; 7); t = (y ^ (y &gt;&gt; 7)) &amp; 0x00AA00AA; y = y ^ t ^ (t &lt;&lt; 7); t = (x ^ (x &gt;&gt;14)) &amp; 0x0000CCCC; x = x ^ t ^ (t &lt;&lt;14); t = (y ^ (y &gt;&gt;14)) &amp; 0x0000CCCC; y = y ^ t ^ (t &lt;&lt;14); t = (x &amp; 0xF0F0F0F0) | ((y &gt;&gt; 4) &amp; 0x0F0F0F0F); y = ((x &lt;&lt; 4) &amp; 0xF0F0F0F0) | (y &amp; 0x0F0F0F0F); x = t; B[0]=x&gt;&gt;24; B[n]=x&gt;&gt;16; B[2*n]=x&gt;&gt;8; B[3*n]=x; B[4*n]=y&gt;&gt;24; B[5*n]=y&gt;&gt;16; B[6*n]=y&gt;&gt;8; B[7*n]=y; } </code></pre> <p>I didn't check if this rotates in the direction you need, if not you might need to adjust the code.</p> <p>Also, keep in mind datatypes &amp; sizes - <code>int</code> &amp; <code>unsigned (int)</code> might not be 32 bits on your platform.</p> <p>BTW, I suspect the book (Hacker's Delight) is essential for the kind of work you're doing... check it out, lots of great stuff in there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload