home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!gatech!concert!samba!usenet
- From: Scott.Maxwell@bbs.oit.unc.edu (Scott Maxwell)
- Subject: Re: Programming-BOOLEAN-compression
- Message-ID: <1992Jul25.052153.15878@samba.oit.unc.edu>
- Sender: usenet@samba.oit.unc.edu
- Nntp-Posting-Host: lambada.oit.unc.edu
- Organization: Extended Bulletin Board Service
- References: <Quentin_Snow.08d3@fcircus.sat.tx.us>
- Date: Sat, 25 Jul 1992 05:21:53 GMT
- Lines: 32
-
- In article <Quentin_Snow.08d3@fcircus.sat.tx.us> Quentin_Snow@fcircus.sat.tx.us (Quentin Snow) writes:
-
- >I am writing a program of which I will be able to enter about 10 - 12
- >YES/NO (boolean) type answers to various questions I write. This
- >information will then be stored into a user structure.
-
- [ ... ]
-
- >There has to be a way for me to store the answers in one "numeric"
- >variable (compressed) form, them extract them. This way I can store the
- >answers in one variable, then read them back when necessary.
-
- [ ... ]
-
- You didn't specify a language. If you're using C, you want to use
- a bit field. If Pascal, use a PACKED ARRAY [whatever..whatever] OF BOOLEAN
- -- though be forewarned that many/most Pascals will store each element as
- a byte, not a single bit. Modula-2 may have something similar; I dunno.
-
- In the unlikely event that you're using a C compiler that doesn't
- support bit fields, get a better compiler. Or, failing that, use shifts
- and masks to store and extract the data in a short int (you said you only
- needed 10-12 bits; a short consists of 16 bits, so there's some waste
- there but not much).
-
- --
- Scott Maxwell (CSMAXWEL@ECUVM1.BITNET or Scott.Maxwell@bbs.oit.unc.edu)
- --
- The opinions expressed are not necessarily those of the University of
- North Carolina at Chapel Hill, the Campus Office for Information
- Technology, or the Experimental Bulletin Board Service.
- internet: bbs.oit.unc.edu or 152.2.22.80
-