Listing 6 Packs an int via a bit-field structure

/* bit2.c: Overlay an integer with a bit field structure
*/
#include <stdio.h>

struct date
{
   unsigned day: 5;
   unsigned mon: 4;
   unsigned year: 7;
};

main()
{
   unsigned int date, year = 92, mon = 8, day = 2;
   struct date *dp = (struct date *) &date;

   dp->mon = mon;
   dp->day = day;
   dp->year = year;
   printf("%04X\n",date);
   return 0;
}

/* OUTPUT:
 * B902 */

/* End of File */