Thanks for your replies guys. Yeah, the extra 6 bits prepended (I wrote appended before sorry) is to chock the length to the next multiple of 8 (56) to give the 7 bytes for transmission.
I had set up a bit of code here to load a bit array. My values are 10bit (as defined by "unsigned varname:10;") and taken from the settings object in each respective getX function. I'm then loading the individual bits in the array as I go, this seems to work fine, but would using fromRawData be more appropriate here, as I still need to convert to a QByteArray for sending with writeDatagram (from the UDP socket class)?
Is it generally easier to convert this QBitArray to a QByteArray or just figure a way to generate the QByteArray in the first place?
for(int i=0;i<10;i++)
{
bitArray->setBit(i+40, (settings->getVH2()&(2^i))==(2^i)); // AND the value with a mask and see if it equals the mask
bitArray->setBit(i+30, (settings->getVL2()&(2^i))==(2^i));
bitArray->setBit(i+20, (settings->getVH1()&(2^i))==(2^i));
bitArray->setBit(i+10, (settings->getVL1()&(2^i))==(2^i));
bitArray->setBit(i+00, (settings->getVL0()&(2^i))==(2^i));
}
QBitArray *bitArray = new QBitArray(56);
for(int i=0;i<10;i++)
{
bitArray->setBit(i+40, (settings->getVH2()&(2^i))==(2^i)); // AND the value with a mask and see if it equals the mask
bitArray->setBit(i+30, (settings->getVL2()&(2^i))==(2^i));
bitArray->setBit(i+20, (settings->getVH1()&(2^i))==(2^i));
bitArray->setBit(i+10, (settings->getVL1()&(2^i))==(2^i));
bitArray->setBit(i+00, (settings->getVL0()&(2^i))==(2^i));
}
To copy to clipboard, switch view to plain text mode
Thanks again for your help guys!
Bookmarks