yodasvideoarcade wrote:Yes, that's what I wanted to do, but you said 896 bytes would be too much, since there's only 1.5kb of RAM.
Is there another data-type I can use? The values are only 0-15, so I could use nibbles instead. Does that data-type exist? A nibble-array?
Or is a bit-array possible, so I can just store a "modified" bit for each position?
16 values need 4 bit, so you could store two values in each byte. You could access them with bitmagic like so:
- Code: Select all
#get value of field 201 (odd)
value1 = field[201/2] & 0b1111;
#get value of field 200 (even)
value2 = field[200/2] >> 4;
or, more generally you could use a function:
- Code: Select all
byte get(byte* field, int position) {
if(position & 1) {
#position is odd
return field[position/2] & 0b1111;
} else {
return field[position/2] >> 4;
}
That way you could store the values of 896 fields in 896/2 = 448 bytes, which might fit.
It's only is a factor of 2, but maybe that's enough. rodot's method could work too, but you'd have to check each item to see if there's one on a specific field, depending on the amount of items this might be slow, the above method is faster at the cost of using more memory.