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
  • "... want to avoid wasting my precious memory space."

    These days, memory is relatively cheap - exactly how "precious" is your memory?

    "... put ... 12-bit-word into ... unsigned int (32 bit) variables?"

    Yes, that would be wasteful!

    You could just put them into short variables - they're 16 bits, so then you'd only be wasting 4 bits per value:
    www.keil.com/.../armccref_babfcgfc.htm

    Would that be good enough?

Reply
  • "... want to avoid wasting my precious memory space."

    These days, memory is relatively cheap - exactly how "precious" is your memory?

    "... put ... 12-bit-word into ... unsigned int (32 bit) variables?"

    Yes, that would be wasteful!

    You could just put them into short variables - they're 16 bits, so then you'd only be wasting 4 bits per value:
    www.keil.com/.../armccref_babfcgfc.htm

    Would that be good enough?

Children