A Boolean array in computer programming is a sequence of values that can only hold the values of true or false. By definition, a Boolean can only be true or false and is unable to hold any other intermediary value. An array is a sequence of data types that occupy numerical positions in a linear memory space. While the actual implementation of a Boolean array is often left up to the compiler or computer language libraries, it is most efficiently done by using bits instead of complete bytes or words. There are several uses for a Boolean array, including keeping track of property flags and aligning settings for physical hardware interfaces.
The idea of a Boolean array stems from original methods that were used to store information on computers where there was very little available memory. The first implementation of a Boolean array took the form of a bit array. This used larger data types such as bytes or long integers to hold information by setting the bits of the data type to true or false. In this way, a single byte that is eight bits long could hold eight different true or false values, saving space and allowing for efficient bitwise operations.
As the size of computer memory increased, the need to use bit arrays declined. While using bits does offer the possibility for bit shifting and using logical operators that allow incredibly fast processing, it also requires custom code to handle these types of operations. Using a standard array structure to hold a sequence of bytes is a simpler solution, but it takes much more memory during program execution. This can be seen when creating an array of 32 Boolean values. With a bit array, the data will only occupy four bytes of memory, but a Boolean type array might occupy anywhere from 32 to 128 bytes, depending on the system implementation.
Some computer programming languages do actually implement a bit array when a Boolean array type is used, although this is not common. A Boolean array has the advantage of being very easy to read when viewing source code. Comparisons and assignments are presented clearly, whereas with a bit array the logical operators "and", "or" and "not" must be used, potentially creating confusing code.
Despite the ease of use, one feature that cannot be used with a Boolean array is a bitmask. A bitmask is a single byte or larger data type that contains a sequence of true and false values relating to multiple conditions. In a single operation, multiple bits can be checked for their true or false states, all at once. With an integer-based array of Boolean values, the same operation would need to be performed with a loop.