Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C, you can manipulate bits with the bitwise operators, such as <code>&amp;</code> and <code>|</code>, as well as the bitshift operators <code>&lt;&lt;</code> and <code>&gt;&gt;</code>.</p> <p>For instance, to turn off the high bit of a given byte, you can do this.</p> <pre><code>char c = 0xBF; // initial value is bit pattern 10111111 c &amp;= 0x7F; // perform AND against the bit pattern 01111111 // final value is bit pattern 00111111 (0x3F) </code></pre> <p>Does that make sense? Obviously, you need to be able to convert from a bit pattern to hex, but that's not too hard.</p> <p>You can use similar masking to extract the bits you want, and put them in an output buffer.</p> <p><strong>Update:</strong></p> <p>You have 64 bits (8 bytes) of input, and want 56 bits (7 bytes) of output.</p> <p>Let's represent your input as the following, where each letter represents a single bit The 'x' bits are the ones you want to throw away.</p> <pre><code>xAAAAAAA xBBBBBBB xCCCCCCC xDDDDDDD xEEEEEEE xFFFFFFF xGGGGGGG xHHHHHHH </code></pre> <p>So you want your final answer to be:</p> <pre><code>AAAAAAAB BBBBBBCC CCCCCDDD DDDDEEEE EEEFFFFF FFGGGGGG GHHHHHHH </code></pre> <p>So in C, we might have code like this:</p> <pre><code>unsigned char data[8] = {/* put data here */}; // chop off the top bit of the first byte data[0] &lt;&lt;= 1; // the bottom bit of data[0] needs to come from the top data bit of data[1] data[0] |= (data[1] &gt;&gt; 6) &amp; 0x01; // use similar transformations to fill in data[1], data[2], ... data[6] // At the end, data[7] will be useless </code></pre> <p>Of course this is not optimized at all, but hopefully you get the idea.</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