From: "Tim Nicholson" Newsgroups: comp.os.msdos.djgpp Subject: Re: Bit field query Date: Thu, 4 Oct 2001 21:26:34 +0100 Organization: Skyforce avionics Limited Lines: 88 Message-ID: <9pigq7$art$1@uranium.btinternet.com> References: <9pidst$kgu$1 AT epos DOT tesco DOT net> <9pigh8$abp$1 AT uranium DOT btinternet DOT com> NNTP-Posting-Host: host62-7-116-236.btinternet.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Correction, it appears in the right most bit! - Sorry, I knew I should put L & R on my boots ;-) Tim "Tim Nicholson" wrote in message news:9pigh8$abp$1 AT uranium DOT btinternet DOT com... > B0 is the LSB and apears in the leftmost bit of the 32 bit field. The > following program will prove this. > > Tim > > //Compile this to show the bit field. > > struct bit_field > { > unsigned int b0 : 1; > unsigned int b1 : 1; > unsigned int b2 : 1; > unsigned int b3 : 1; > unsigned int b4 : 1; > unsigned int b5 : 1; > unsigned int b6 : 1; > unsigned int b7 : 1; > }; > > int main(void) > { > struct bit_field my_bits; > unsigned int *my_word; > short int i; > > my_word = (unsigned int *) &my_bits; > > *my_word = 0; > > my_bits.b0 = 1; > my_bits.b5 = 1; > for (i=0; i<32;i++) > { > printf("%d", (*my_word) & 0x80000000 ? 1:0); > *my_word <<= 1; > } > printf("\n"); > } > "Graham Warren" wrote in message > news:9pidst$kgu$1 AT epos DOT tesco DOT net... > > I have a question about bit-fields. > > > > In a program I have defined a bit-field using the code shown below. > > > > > > /* define bit-field */ > > > > struct { > > unsigned int b0 : 1; > > unsigned int b1 : 1; > > unsigned int b2 : 1; > > unsigned int b3 : 1; > > unsigned int b4 : 1; > > unsigned int b5 : 1; > > unsigned int b6 : 1; > > unsigned int b7 : 1; > > } bit_field; > > > > /* */ > > > > > > > > My questions are: would bit_field.b0 be the furthest left or furthest > right > > bit if the byte is written out 00000000? > > Would this change if more bits were defined in the bit field to make it > > spill over into a larger than 1 byte area? > > > > Also which bit in 00000000 is referred to as the most-significant and > which > > is the least-significant? > > > > > > Thankyou > > Graham Warren > > > > > >