Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert 8 17-bit integers into 17 8-bit integers efficiently
    primarykey
    data
    text
    <p>Okay, I have the following problem: I have a set of 8 (unsigned) numbers that are all 17bit (a.k.a. none of them are any bigger than 131071). Since 17bit numbers are annoying work work with (keeping them in a 32-bit int is a waste of space), I would like to turn these into 17 8-bit numbers, like so:</p> <p>If I have these 8 17-bit integers:</p> <pre><code>[25409, 23885, 24721, 23159, 25409, 23885, 24721, 23159] </code></pre> <p>I would turn them into a base 2 representationL</p> <pre><code>["00110001101000001", "00101110101001101", "00110000010010001", "00101101001110111", "00110001101000001", "00101110101001101", "00110000010010001", "00101101001110111"] </code></pre> <p>Then join that into one big string:</p> <pre><code>"0011000110100000100101110101001101001100000100100010010110100111011100110001101000001001011101010011010011000001001000100101101001110111" </code></pre> <p>Then split that into 17 strings, each with 8 chars:</p> <pre><code>["00110001", "10100000", "10010111", "01010011", "01001100", "00010010", "00100101", "10100111", "01110011", "00011010", "00001001", "01110101", "00110100", "11000001", "00100010", "01011010", "01110111"] </code></pre> <p>And, finally, convert the binary representations back into integers</p> <pre><code>[49, 160, 151, 83, 76, 18, 37, 167, 115, 26, 9, 117, 52, 193, 34, 90, 119] </code></pre> <p>This method works, but it's not very efficient, I am looking for something more efficient than this, preferrably coded in C++, since that's the language I am working with. I just can't think of any way to do this more efficient, and 17-bit numbers aren't exactly easy to work with (16-bit numbers would be much nicer to work with). </p> <p>Thanks in advance, xfbs</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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