ba.setBit(5, true);
ba.setBit(7, true);
for (int i = 0; i < ba.size(); ++i)
text += ba.testBit(i) ? "1": "0";
qDebug() << text;
QBitArray ba(10);
ba.setBit(5, true);
ba.setBit(7, true);
QString text;
for (int i = 0; i < ba.size(); ++i)
text += ba.testBit(i) ? "1": "0";
qDebug() << text;
To copy to clipboard, switch view to plain text mode
You might like to reverse bit order.
If you are manipulating a small number of bits then direct use of an unsigned int is also a possibility.
unsigned int bitmap = 0;
bitmap |= 1 << 5;
bitmap |= 1 << 7;
qDebug
() <<
QString::number(bitmap,
2);
unsigned int bitmap = 0;
bitmap |= 1 << 5;
bitmap |= 1 << 7;
qDebug() << QString::number(bitmap, 2);
To copy to clipboard, switch view to plain text mode
Bookmarks