Note that this is great, but according to ANSI sizeof(Bits) == sizeof(int), not sizeof(Bits) == sizeof(char). Also according to ANSI, int must be at least a 16-bit value. Bob Ammerman RAm Systems ----- Original Message ----- From: "Ashley Roll" To: Sent: Monday, December 03, 2001 3:30 PM Subject: Re: [pic]:Accessing a var as a byte or bits in C > Hi > > typedef union { > struct { > int Bit0 : 1; > int Bit1 : 1; > int Bit2 : 1; > int Bit3 : 1; > int Bit4 : 1; > int Bit5 : 1; > int Bit6 : 1; > int Bit7 : 1; > } Bits; > unsigned char Value; > } BitDataByte; > > BitDataByte myData; > > myData.Value = 42; > > myData.Bits.Bit0 = 1; > > Will get you started.. the ": 1" tells the compiler to allocate 1 bit to the > element, but you can allocate any number. So you can have a 2 or 3 or 14 bit > number as you choose. more details should be in your local C language book > :) > > Cheers, > Ash. > > --- > Ashley Roll > Digital Nemesis Pty Ltd > www.digitalnemesis.com > Mobile: +61 (0)417 705 718 > > > > > > -----Original Message----- > > From: pic microcontroller discussion list > > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Sean H. Breheny > > Sent: Tuesday, 4 December 2001 8:47 AM > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: [pic]:Accessing a var as a byte or bits in C > > > > > > What is the syntax? I've been using C for 9 years (mostly on > > PCs but also > > on microcontrollers) and don't recall ever seeing it! > > > > Sean > > > > At 03:43 PM 12/3/01 -0500, you wrote: > > >Normal C has bitfields in it. Usually you use them in > > structs or unions. > > >Problem is you don't usually know which bit is assigned, so I prefer > > >assembly at that level of detail. > > >/\/\/\/*=Martin > > > > ---------------------------------------------------- > > 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 > > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads