MyWebUniversity.com Home Page
 



Darwin Mac OS X man pages main menu
BITSTRING(3)             BSD Library Functions Manual             BITSTRING(3)

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

SYNOPSIS
     ##include <>

     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 NUL 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 non-zero if the zero-based numbered bit
     bit of bit string name is set, and 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 
           #include 

           #define LPRBUSYBIT            0
           #define LPRFORMATBIT          1
           #define LPRDOWNLOADBIT        2
           #define LPRAVAILABLEBIT       9
           #define LPRMAXBITS            10

           makelpravailable()
           {
                   bitstrt bitdecl(bitlist, LPRMAXBITS);
                   ...
                   bitnclear(bitlist, 0, LPRMAXBITS - 1);
                   ...
                   if (!bittest(bitlist, LPRBUSYBIT)) {
                           bitclear(bitlist, LPRFORMATBIT);
                           bitclear(bitlist, LPRDOWNLOADBIT);
                           bitset(bitlist, LPRAVAILABLEBIT);
                   }
           }

SEE ALSO
     malloc(3)

HISTORY
     The bitstring functions first appeared in 4.4BSD.

4th Berkeley Distribution        July 19, 1993       4th Berkeley Distribution
Darwin Mac OS X man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™