Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bitstring(3) — BSD/386 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

malloc(3)

BITSTRING(3)                BSD Programmer's Manual               BITSTRING(3)

NAME
     bitalloc, bitclear, bitdecl, bitffs, bitnclear, bitnset, bitset,
     bitstrsize, bittest - bit-string manipulation macros

SYNOPSIS
     #include <bitstring.h>

     bitstrt *
     bitalloc(int nbits)

     bitdecl(bitstr name, int nbits)

     bitclear(bitstr name, int bit)

     bitffc(bitstr name, int nbits, int *value)

     bitffs(bitstr name, int nbits, int *value)

     bitnclear(bitstr name, int start, int stop)

     bitnset(bitstr name, int start, int stop)

     bitset(bitstr name, int bit)

     bitstrsize(int nbits)

     bittest(bitstr name, int bit)

DESCRIPTION
     These macros operate on strings of bits.

     The macro bitalloc() returns a pointer of type ``bitstrt *'' to suffi-
     cient space to store nbits bits, or NULL if no space is available.

     The macro bitdecl() allocates sufficient space to store nbits bits on
     the stack.

     The macro bitstrsize() returns the number of elements of type bitstrt
     necessary to store nbits bits.  This is useful for copying bit strings.

     The macros bitclear() and bitset() clear or set the zero-based numbered
     bit bit, in the bit string name.

     The bitnset() and bitnclear() macros set or clear the zero-based num-
     bered bits from start to stop in the bit string name.

     The bittest() macro evaluates to zero if the zero-based numbered bit bit
     of bit string name is set, and non-zero otherwise.

     The bitffs() macro stores in the location referenced by value the zero-
     based number of the first bit set in the array of nbits bits referenced
     by name. If no bits are set, the location referenced by value is set to
     -1.

     The macro bitffc() stores in the location referenced by value the zero-
     based number of the first bit not set in the array of nbits bits refer-
     enced by name. If all bits are set, the location referenced by value is
     set to -1.

     The arguments to these macros are evaluated only once and may safely have
     side effects.

EXAMPLE
           #include <limits.h>
           #include <bitstring.h>

           #define LPR_BUSY_BIT            0
           #define LPR_FORMAT_BIT          1
           #define LPR_DOWNLOAD_BIT        2
           #define LPR_AVAILABLE_BIT       9
           #define LPR_MAX_BITS            10

           make_lpr_available()
           {
                   bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
                   ...
                   bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
                   ...
                   if (!bit_test(bitlist, LPR_BUSY_BIT)) {
                           bit_clear(bitlist, LPR_FORMAT_BIT);
                           bit_clear(bitlist, LPR_DOWNLOAD_BIT);
                           bit_set(bitlist, LPR_AVAILABLE_BIT);
                   }
           }

SEE ALSO
     malloc(3)

HISTORY
     The bitalloc functions are currently under development.

4th Berkeley Distribution       March 27, 1993                               2






































Typewritten Software • bear@typewritten.org • Edmonds, WA 98026