PDA

View Full Version : Using byte variable for storing two different values<100 at same time?



CuriousOne
- 2nd August 2018, 07:43
Hello.
I have a project, where I have to store some values in range of 1-99, 100 values total. Planning to use array for that, but since using low end PIC, can't store too many data in array, but maybe it is possible to split array byte somehow? I mean, byte variable can take any value from 1 to 255, but I need to store two values, each in 1-99 range, so maybe it is possible to store two such values in single byte ?

HenrikOlsson
- 2nd August 2018, 11:37
The decimal value 99 requires 7 bits so most you can save by packing values is 1 bit per value with the added overhead and complexity of unpacking them.

If these values are to be in RAM (which I believe is the case since you mention an array) then I'd say it's not worth the effort but if the values aren't changing and are to be held in "ROM" then, as it happens, the low end PICs have a program memory word size of 14 bits so you could put two 7-bits values into one program memory word.

/Henrik.

CuriousOne
- 2nd August 2018, 15:05
Nope, these are pre-defined values, they do not change during program execution, in fact, you gave me good idea, I will flash them to EEPROM during flashing and just use READ statement to read them from corresponding eeprom cell.