Hello all I am assigned to make a bit array class and I would like some assistance on some definitions of the class. I need to make a Set(), Unset(),Query(), and Flip() member function and all of these have unsigned int variables as parameters. Set() should set that bit to 1, without affecting any others. Unset() should set that bit to 0, without affecting any others. Flip() should change that bit to its opposite, without affecting any others. Query() should return true if that bit is currently 1, and it should return false if that bit is currently . If anyone can help that would be great.
Choose a container to store the bits – there are some problems with std::vector<bool>(http://stackoverflow.com/questions/17794569/why-is-vectorbool-not-a-stl-container), so I'd suggest std::array<bool, N> (maybe std::deque<bool> will also work but it's not parameterized on N) and then try and complete the following list. A standard library container would be preferable to the C-style array you're using at present at memory management would be in-built and you can also use other library facilities:
The actual bitmath is correct, but the indexing isn't. barray is an array of unsignedchars, not of bits. The first CHAR_BIT bits are part of the first element of the array, the second CHAR_BIT bits are part of the second, and so on.
In other words, the nth bit is the (n % CHAR_BIT) part of the char at offset n / CHAR_BIT, allowing for integer division.
Note:
The size of char is always 1. However, the number of bits in a char is not always 8 (8 is the minimum). While you can probably get away with the 8-bit assumption in class, this is not a valid assumption especially on certain embedded platforms. You can get the number of bits in a char by using the macro CHAR_BIT from <climits>.
im not sure what exactly im supposed to do with that im not allowed to use climit or bitset libraries. Im not sure how Im able to change these bits with just the standard libraries. I also need assistance with the operator<<(ostream& os, const BitArray& a) function. Im supposed to format is the entire array, printed as one continuous sequence of bits, inside parintheses.
oh alright its running now but I have one more question and ill be out of your hair, along with this program I need to create a seive.h file and use it to list all the prime numbers that are less than the arraySize. here is what I have but its not running: