Big Bits

This class starts very simple. Just an unsigned integer to hold how many bytes the array is managing and a unsigned character pointer that will hold onto a dynamically allocated array of bytes for us.

Now we don't want to leak memory, crash or just be unusable so lets add the constructor, trilogy of evil (destructor, copy constructor, assignment operator), accessors, and mutators.

So now lets get into the meat of the code. the operators. Let's to the easy ones first. The AND OR XOR and Negation operators.

These operators are really no different the any other bitwise operation. We just have to do it multiple times.

Header:

CPP

Now to the slightly more challenging section the shift operators. the shift operators are more challenging because we do not want to loose the values of a bit when it shifts off or one byte onto another so it byte one is 10010011 and byte 2 is 10010011 we want their shifted values to be 00100111 and 00100110 not 00100110 and 00100110

Header:

CPP

 

So there we have it, a manual implementation of the bitarray class.

Here is the compiled class.

Header:

CPP