Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QBitArray class provides an array of bits. More...
#include <qbitarray.h>
Inherits QByteArray.
Because QBitArray is a QMemArray, it uses explicit sharing with a reference count.
A QBitArray 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 setBit() and clearBit() because some tricks are required to implement single-bit assignments.
Example:
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]
When a QBitArray is constructed the bits are uninitialized. Use fill() to set all the bits to 0 or 1. The array can be resized with resize() and copied with copy(). Bits can be set with setBit() and cleared with clearBit(). Bits can be toggled with toggleBit(). A bit's value can be obtained with testBit() and with at().
QBitArray supports the & (AND), | (OR), ^ (XOR) and ~ (NOT) operators.
See also Collection Classes, Implicitly and Explicitly Shared Classes and Non-GUI Classes.
See also fill().
See also operator[]().
See also setBit() and toggleBit().
See also detach().
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().
Reimplemented from QMemArray.
fill() resizes the bit array to size bits if size is nonnegative.
Returns FALSE if a nonnegative size was specified and the bit array could not be resized; otherwise returns TRUE.
See also resize().
If the arrays have different sizes, the AND operation uses 0 for the missing bits, as the following example demonstrates:
QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a &= b; // a = [1 0 0]
See also operator|=(), operator^=() and operator~().
The returned QBitVal is a context object. It makes it possible to get and set a single bit value by its index position.
Example:
QBitArray a( 3 ); a[0] = 0; a[1] = 1; a[2] = a[0] ^ a[1];
The functions testBit(), setBit() and clearBit() are faster.
See also at().
Implements the [] operator for constant bit arrays.
The result has the length of the longest bit array of the two, with the bits missing from the shortest array taken as 0.
Example:
QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a ^= b; // a = [0 0 1]
See also operator&=(), operator|=() and operator~().
The result has the length of the longest bit array of the two, with the bits missing from the shortest array taken as 0.
Example:
QBitArray a( 3 ), b( 2 ); a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b[0] = 1; b[1] = 0; // b = [1 0] a |= b; // a = [1 0 1]
See also operator&=(), operator^=() and operator~().
Example:
QBitArray a( 3 ), b; a[0] = 1; a[1] = 0; a[2] = 1; // a = [1 0 1] b = ~a; // b = [0 1 0]
If the array is expanded, the new bits are set to 0.
See also size().
Equivalent to:
if ( value ) setBit( index ); else clearBit( index );
See also clearBit() and toggleBit().
Sets the bit at position index (sets it to 1).
See also clearBit() and toggleBit().
See also resize().
See also setBit() and clearBit().
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().
See also QBitArray::operator&=().
See also Format of the QDataStream operators.
See also Format of the QDataStream operators.
See also QBitArray::operator^().
See also QBitArray::operator|=().
This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.
Copyright © 2002 Trolltech | Trademarks | Qt version 3.0.4
|