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
  • Is it possible to put 4k of this 12-bit-word into 1.5k unsigned int (32 bit) variables?

    Of course it is possible, if you have enough CPU power and are willing to spend it on packing/unpacking the data.

    Basically, you will need to write functions for reading/writing the packed array. These functions need to calculate in which 32-bit word(s) the required 12-bit variable is stored, and extract it with a couple of boolean operations and bit-shifts.

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

    Of course it is possible, if you have enough CPU power and are willing to spend it on packing/unpacking the data.

    Basically, you will need to write functions for reading/writing the packed array. These functions need to calculate in which 32-bit word(s) the required 12-bit variable is stored, and extract it with a couple of boolean operations and bit-shifts.

Children
No data