home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_11 / allison / bit.h < prev    next >
C/C++ Source or Header  |  1993-09-01  |  516b  |  24 lines

  1. LISTING 3 - Declarations for Bit Access Functions
  2. /* bit.h:    Bitwise functions for unsigned ints */
  3. #ifndef BIT_H
  4. #define BIT_H
  5.  
  6. #include <stdio.h>
  7. #include <limits.h>
  8.  
  9. #define mask1(i)    (1u << i)
  10. #define mask0(i)   ~(1u << i)
  11.  
  12. #define set(n,i)     (n | mask1(i))
  13. #define reset(n,i)   (n & mask0(i))
  14. #define toggle(n,i)  (n ^ mask1(i))
  15. #define test(n,i)    !!(n & mask1(i))
  16.  
  17. #define nbits(x) (sizeof(##x##) * CHAR_BIT)
  18.  
  19. unsigned fputb(unsigned, FILE *);
  20. unsigned fgetb(FILE *);
  21. unsigned count(unsigned);
  22.  
  23. #endif
  24.