Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cannot read less than one byte at a time. However you can use bitmasks and shift operations to set the last two bits to <code>0</code> (if you are storing 16), and carry the two unused bits you removed for the next value. This will probably made the decoding operation a lot more complicated and expensive though.</p> <p>How about decoding the values 8 by 8 (you can read 14 chars = 112 bits = 8 * 14 bits)? I have NOT tested this code, and there are probably some typos in there. It does compile but i don't have your file to test it:</p> <pre><code>#include &lt;stdio.h&gt; int main(){ FILE *file = fopen ("...", "rt"); // loop variable unsigned int i; // temporary buffer char buffer[14]; // your decoded ints int decoded[8]; while(fgets(buffer, 14, file) != NULL) { int cursor = 0; // we do this loop only twice since the offset resets after 4 * 14 for(i = 0; i &lt;= 4; i+= 4){ // first decoded int is 16 bits decoded[i+0] = (buffer[cursor++] | (buffer[cursor++] &lt;&lt; 8)); // second is 2 + 8 + 8 = 18 bits (offset = 2) decoded[i+1] = (decoded[i+0] &gt;&gt; 14) | buffer[cursor++] &lt;&lt; 2 | buffer[cursor++] &lt;&lt; 10; // third is 4 + 8 + 8 = 20 bits (offset = 4) decoded[i+2] = (decoded[i+1] &gt;&gt; 14) | buffer[cursor++] &lt;&lt; 4 | buffer[cursor++] &lt;&lt; 12; // next is 6 + 8 = 14 bits (offset = 6) decoded[i+3] = (decoded[i+2] &gt;&gt; 14) | buffer[cursor++] &lt;&lt; 6; } // trim the numbers to 14 bits for(i = 0; i &lt; 8; ++i) decoded[i] &amp;= ((1 &lt;&lt; 15) - 1); } fclose(file); } </code></pre> <p>Note that I don't do anything with the decoded ints, and I write on the same array over and over again, this is just an illustration. You can factorize the code more but I unrolled the loops and commented the operations so that you see how it works.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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