I'm afraid I'm not familiar with the term "bit array".
One use of individual bits is as a way to make your resource usage more efficient. A bit only has 2 states ON(1) and OFF(0). These states can be used to represent individual yes/no, true/false, etc. values in a more efficient manner by storing 8 values into a single Byte rather than mulitple Bytes.
They're also used in compression and encryption algorithms, but I really can't speak intelligently on either of those topics.
Hi guyzz !!
I have tried scouting the internet but could not get a suitable explanation.
Please tell me with an example as to what are bit arrays and what are their applications.
Any help would be greatly appreciated.
Yeah like Evan said, you can use bitset to create an array of bits. I heard also that vector<bool> also performs a similar function of creating elements that are only 1 bit in length (oddly enough, since the data type bool is a byte in length when used normally in C++).
To answer your question, in C++ every other type of data is at least 8 bits in length, that is, a character (for example) is represented by eight zeroes or ones which is the binary equivalent of 0 through 255. But you might want to use a bit array if you're performing many many calculations on data where you only need two values (0 or 1). Since it would then be 1/8th the size of a character, it's more efficient space-wise and possibly faster, depending on various circumstances.
As to its applications, there are many reasons why you might need a big array of things that have a value of only true or false. But it's only come up once or twice for me, and it would be a little confusing to explain those without a lot of context.
I heard also that vector<bool> also performs a similar function of creating elements that are only 1 bit in length (oddly enough, since the data type bool is a byte in length when used normally in C++).
This is true, I almost forgot! Check the last paragraph of this page.
Note std::vector<bool> is depreciated. Its creation was pointless and a mistake. std::vector<char> is a better choice versus std::vector<bool>. But using std::bitset would be better choice than either one depending on the need.