TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: KURT J. TISCHER
from: HERMAN SCHONFELD
date: 1997-03-23 09:25:00
subject: Bit Fields

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)) ???
KT>        I'm new to C/C++, but isn't it possible to declare boolean
KT>variables?  Wouldn't that be the kind of variable you are looking for?
KT>1/0, True/False, On/Off kinda thing?
no you can't. Why would it matter anyway? It's much slower than using ints.
try this anyway..
struct  bit_field {
        int bit_1        : 1;
        int bits_2_to_5  : 4;
        int bit_6        : 1;
        int bits_7_to_16 : 10;
} bit_var;
but if you need 1 bit variables
struct bit_field {
           int  bit1 :1
            .
            .
            .
           int  bit16 :1
} bit_var
KT>        I'll have to look into this one.  Good question.
... Error 763 - Hard disk not ready, close door.
--- Ezycom V1.48g0 01fd016b
---------------
* Origin: Fox's Lair BBS Bris Aus +61-7-38033908 V34+ Node 2 (3:640/238)

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™.