delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/04/17:15:06

From: "Graham Warren" <Moosehead AT tesco DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Bit field query
Date: Thu, 4 Oct 2001 20:43:59 +0100
Organization: Tesco ISP
Lines: 35
Message-ID: <9pidst$kgu$1@epos.tesco.net>
NNTP-Posting-Host: dialup.62-172-20-29.tesco.net
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019