ANSI "C" supports bitfields, which are a special type of structure field. In ANSI "C" multiple bitfields are crunched together into one "int" sized value (note: NOT a char!). The syntax is like this: typedef struct { int field_1 : 1; // single bit field int field_2 : 1; int field_3 : 5; // 5-bit field } bitfield_struct; you can do this too: typedef union { int as_integer; bitfield_struct as_fields; } bitfield_union; bitfield_union myvar; myvar.as_fields.field_3 = 2; myvar.as_fields.field_1 = 0; save_it( myvar.as_integer ); Bob Ammerman RAm Systems ----- Original Message ----- From: "Sean H. Breheny" To: Sent: Monday, December 03, 2001 12:27 PM Subject: Re: [pic]:Accessing a var as a byte or bits in C > Hi Andrew, > > Is this specific to HiTech? I have never seen a "normal" C compiler which > had a bit variable type, and I thought that either the ANSI or K&R > standards did not call for such a type. > > Sean > > At 11:31 AM 12/3/01 -0700, you wrote: > >Re: > > > >>In Hitech C, is it possible to access the same variable as two > >>different types in C, specifically bits and bytes ? > >>For example I want some bit variables for various option flags, but > >>want to access them all as a single byte when saving/loading them to > >>eeprom. > >> > >>Can unions be used to do this ? > > > > > >Yes. > >-- > > > > ______________________________________ > > Andrew E. Kalman, Ph.D. aek@pumpkininc.com > > > >-- > >http://www.piclist.com hint: PICList Posts must start with ONE topic: > >[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > > ---------------------------------------------------- > Sign Up for NetZero Platinum Today > Only $9.95 per month! > http://my.netzero.net/s/signup?r=platinum&refcd=PT97 > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads