This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Packing 12-bit date into int

Hi,
my i have a 12-bit AD-Converter and want to avoid wasting my precious memory space.

Is it possible to put 4k of this 12-bit-word into 1.5k unsigned int (32 bit) variables?

This stuff should be adressable as a kind of ring-buffer.

Think a struct with union should do. But as i'am a relative beginner i'am not sure about the syntax.

Parents
  • It might be easier to use a 6k array of bytes. Then there are only two pack alternatives for a 12-bit value. Even ADC values starts with a byte and and requires 4 bit from next byte. Odd ADC values should take 4 bits and then the next byte.

    It is trivial to convert from ADC value n into the start offset in the byte array.

Reply
  • It might be easier to use a 6k array of bytes. Then there are only two pack alternatives for a 12-bit value. Even ADC values starts with a byte and and requires 4 bit from next byte. Odd ADC values should take 4 bits and then the next byte.

    It is trivial to convert from ADC value n into the start offset in the byte array.

Children