home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / codelib9 / v_11_11 / allison / bit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  516 b   |  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.