Hi All , I have a simple question Iam now making a c# huffman compressor so I read the text file and decode it using the huffman tree that I will make ,I just have a simple problem which is writing bits
I used the bitarray class but there is a problem is that when I use is that the value of the bit will be true or false and when I write this bit to a file (Supposed compressed one) so it is written true or false not as a single bit or in other meaning the sizze of one bit on a file will be 4byte because it is wrriten as true(4 bytes) or false(4 bytes) I hope you understand me
thanks in advance

This is something I used to make a binary clock with. It interprets an integer as an array of 32 bits.

struct IntBits
    {
        private int _bits;

        public IntBits(int InitialBitValue)
        {
            _bits = InitialBitValue;
        }

        //declare indexer
        public bool this[int index]
        {
            get
            {
                return (_bits & (1 << index)) != 0;
            }
            set
            {
                if (value)
                    _bits |= (1 << index);  //set bit index 1
                else
                    _bits &= ~(1 << index); //set bit index 0           
            }
        }
    }

I got it from the net or out of a book I don't remember.
Hope it helps.

You could also read this.

Use BitConverter class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.