typedef unsigned int Uint;

class Bpack {

// static const int LPOS = 8*sizeof(int) -1;
static const int LPOS;
static const Uint Mask[24];

private:
	Uint buf;
	int bx;

	Uint getmask(int s)	{return Mask[s-1];}		//used in upack()

public:
	Bpack():	bx(LPOS), buf(0)				{}
	Bpack(int start):	bx(LPOS), buf(start)	{}

	Uint pack(Uint bits, int len);
	Uint upack(int len);
	Uint flush()					{return buf;}
	void display(Uint val=0);		//print buf if val 0
};
