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 Bytes

Hi,

The literature I'm reading suggests that I can specify the number of bits a certain data type must occupy, and that I can possibly store several of these packed variables into the same byte for reduced storage space.

typedef struct{
unsigned int a: 4;
unsigned char b: 2;
} my_type;

I tried the above but it just truncates the values assigned and stores them in separate two byte wide and 1 byte wide spaces respectively. What's the trick?

Regards,
Murray R. Van Luyn.

Parents
  • My comment wasn't instigated from his description of Kiel on the other forum, rather it was an expression of my disdain for bit fields in C.

    There's many ways to torture and 8051, but few come close to the underlying assembly that results from bit fielding. I guess its OK if it simply has to be done in one or two spots, but anything more than that and its bad news.

Reply
  • My comment wasn't instigated from his description of Kiel on the other forum, rather it was an expression of my disdain for bit fields in C.

    There's many ways to torture and 8051, but few come close to the underlying assembly that results from bit fielding. I guess its OK if it simply has to be done in one or two spots, but anything more than that and its bad news.

Children