Hello.
I set an arbitrary array
QBitArray msg (8); msg.setBit(7, listBit.at(1).toInt()); msg.setBit(6, listBit.at(2).toInt()); msg.setBit(5, listBit.at(3).toInt()); msg.setBit(4, listBit.at(4).toInt()); msg.setBit(3, listBit.at(5).toInt()); msg.setBit(2, listBit.at(6).toInt()); msg.setBit(1, listBit.at(7).toInt()); msg.setBit(0, listBit.at(8).toInt()); at the same time the array can be 16 bits and so on. I need to get the value out of it and output it.
There is a function on the Internet
QByteArray bitsToBytes(const QBitArray &bits) { QByteArray bytes; bytes.resize(bits.size()/8); // Convert from QBitArray to QByteArray for(int b=0; b<bits.count(); ++b) bytes[b/8] = (bytes.at(b/8) | ((bits[b]?1:0)<<(b%8))); return bytes; } However, the result is incorrect. Please tell me how to implement