TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RICK BISCHOFF
from: BRUCE ROESER
date: 1997-03-23 22:25:00
subject: Bit Fields

-=> Quoting Rick Bischoff to All <=-
Hey Rick:
 RB> Does anyone know how to declare a variable that holds only one bit of
 RB> information.. (You know only two values (0 or 1)) ??? 
 RB> Thanks..
  Sure, but I believe the bit field must be part of a structure
  definition.  For example, Let's suppose you wanted to define a
  variable that had a number of single-bit fields.  You could define
  it like this:
typedef struct {
    int     bit0    :1;     // This field is 1 bit.
    int     bit1    :1;     // Also 1 bit.
    int     bit2_7  :6;     // 6-bit field.
    char    bit8_f;         // 8 bit field.
} BitMap;
  You would then declare a variable of type BitMap and address the
  individual elements as you would in any structure definition, but the
  individual fields would only hold values valid for their size.
-bwr-
... Fidonet: The Information Winding Country Road.
--- GEcho 1.20/Pro
---------------
* Origin: (1:363/319)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.