/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#ifndef BITS_H
#define BITS_H

// various
#define MIN(a,b) ((a<b)?a:b)
typedef unsigned char UCHAR;
typedef int BOOL;
const int BITS_PR_CHAR = 8;

//**********************************************************************
//
//  Class definitions:
//
//    BitString : char array containing bits
//
//**********************************************************************

// class for char array containing bits
class BitString {
   private:
      // body of bytes
      char *Body;
      // length of body in bytes
      int Len;
      // current position in bits
      int CurrPos;
   public:
      // constructor
      BitString();
      // destructor
      ~BitString();
      // add bits
      void AddBits(int Value,int NoBits);
      // get bits
      int GetBits(int NoBits);
      int GetBitsSigned(int NoBits);
      // set string
      void SetString(void *Buffer,int Size);
      // get string
      void GetString(void *Buffer,int BufferSize,int *ReturnLen);
      void GetStringRev(void *Buffer,int BufferSize,int *ReturnLen);
      // end of string ?
      BOOL EndString(int Size = 0);
      // size of string
      int SizeString();
   };

#endif // BITS_H
