Hi, this might get a little mathy, so be warned.
Alright, I have to store a bunch of 12 bit values in an array. Currently, I am storing them as byte values. So I have an array sort of like this (this syntax may be wrong, but you will get the idea)
byte myArray[1000][12] =
{
{ // This is the first of the 1000 indexes
{1,1,1,1,1,1,1,1,1,1,1,1} // This takes up 12 bytes, but could be done in 2 bytes
}
};
So obviously, I am wasting a ton of space (roughly 10 kb for this array alone). Keep in mind that I want to store a minimum of 8 of these arrays, so the wasted space really starts to add up. So I would like to store these numbers as efficiently as possible. This would require converting these 12 bit numbers to base 10, and storing them as ints (which only take up 2 bytes). Is there an easy way to convert these 12 bit numbers to ints, and vice versa?
Brief Overview of My Project:
Currently my project is made to cycle through this array and buffer each of the 1000 indexes. As the program is cycling through the array, it buffers out one of the 1000 indexes, waits 30ms, then buffers out the next one. When the buffer is sent out, it switches 12 digital pins (LOW or HIGH obviously), depending on which of 12 bits is high. Using this binary array makes it easy, but wastes space. If I stored each of the 100 frames as an int, I would have to convert each of these buffers from an int to the 12 bit version for switching the right pins. Also, this has to be done pretty quickly.
TLDR: I need to store a 12 bit number as an int for maximum storage efficiency. Advice for quickly converting to and from the more efficient int data type.