The QBitArray class provides an array of bits. (details) (complete member list)
#include <qbitarry.h>
Inherits QByteArray.
A bit array is a special byte array that can access individual bits and perform bit-operations (AND, OR, XOR and NOT) on entire arrays or bits.
Bits can be manipulated by the setBit() and clearBit() functions, but it is also possible to use the indexing [] operator to test and set individual bits. The [] operator is a little slower than the others, because some trics are required to implement bitwise assignments.
Example of use:
QBitArray a(3);
a.setBit( 0 );
a.clearBit( 1 );
a.setBit( 2 ); // a = [1 0 1]
QBitArray b(3);
b[0] = 1;
b[1] = 1;
b[2] = 0; // b = [1 1 0]
QBitArray c;
c = ~a & b; // c = [0 1 0]
Constructs an empty bit array.
Constructs a bit array of size bits. The bits are uninitialized.
Clears the bit at position i (sets it to 0).
See also: setBit() and toggleBit().
Returns a deep copy of the bit array.
See also: detach().
Detaches from shared bit array data and makes sure that this bit array is the only one referring the data.
If multiple bit arrays share common data, this bit array dereferences the data and gets a copy of the data. Nothing will be done if there is just a single reference.
See also: copy().
Fills the bit array with v (1's if v is TRUE, or 0's if v is FALSE). Will resize the bit array to size bits if size is nonnegative. Returns FALSE if a nonnegative size was specified and if the bit array could not be resized, otherwise returns TRUE.
See also: resize().
Performs the AND operation between all bits in this bit array and a. Returns a reference to this bit array.
The two bit arrays must have the same size.
Example of use:
QBitArray a(3), b(3);
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 0; b[1] = 0; b[2] = 1; // b = [0 0 1]
a &= b; // a = [0 0 1]
See also: operator|=() and operator^=().
Performs the XOR operation between all bits in this bit array and a. Returns a reference to this bit array.
The two bit arrays must have the same size.
Example of use:
QBitArray a(3), b(3);
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 0; b[1] = 0; b[2] = 1; // b = [0 0 1]
a ^= b; // a = [1 0 0]
See also: operator&=() and operator|=().
Returns a bit array which contains the inverted bits of this bit array.
Example of use:
QBitArray a(3);
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
QBitArray b = ~a; // b = [0 1 0]
Performs the OR operation between all bits in this bit array and a. Returns a reference to this bit array.
The two bit arrays must have the same size.
Example of use:
QBitArray a(3), b(3);
a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1]
b[0] = 0; b[1] = 0; b[2] = 1; // b = [0 0 1]
a |= b; // a = [1 0 1]
See also: operator&=() and operator^=().
Resizes the bit array to size bits. Returns TRUE if the bit array could be resized.
When expanding the bit array, the new bits will be uninitialized.
See also: size().
Sets the bit at position i (sets it to 1).
See also: clearBit() and toggleBit().
Returns the size (number of bits) of the bit array.
See also: resize().
Returns TRUE if the bit at position i is set.
See also: setBit() and clearBit().
Toggles the bit at position i.
If the previous value was 0, the new value will be 1. If the previous value was 1, the new value will be 0.
See also: setBit() and clearBit().
Returns the AND result between the bit arrays a1 and a2.
See also: QBitArray::operator&().
Returns the OR result between the bit arrays a1 and a2.
See also: QBitArray::operator|().
Returns the XOR result between the bit arrays a1 and a2.
See also: QBitArray::operator^().
Writes a bit array to the stream.
Reads a bit array from the stream.
This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.
It was generated from the following files: