PDA

View Full Version : bit by bit -> Binary File Reader



2lights
1st October 2013, 07:53
Good Day,

I have a binary field, that I need to read bit by bit
Is there a way to read in the actual binary values of a file.

I got this so far, but it reads per byte(quint8)



QDataStream in(&fileLoadBinary);
int fileSize = fileLoadBinary.size();
int i = 0;
QStringList strngLst;
quint8 tempVariable;
while(i < fileSize)
{
in >> tempVariable;
qDebug() << tempVariable;
strngLst.append(QString(tempVariable));
i++;
}
qDebug() << strngLst;


I want the actual binary values of the file(bit by bit)
Whats the way forward?

Help is much appreciated :)
Kind Regards

high_flyer
1st October 2013, 08:05
You can't read less than a byte each time.(at least, not to my knowledge)
But why would you need a bit by bit read?
I am sure the reason will turn out to be not valid.

Radek
1st October 2013, 08:06
No way forward. The smallest amount of data you can access is a byte. Reading bit by bit isn't possible. Make a "buffered input stream" that reads byte by byte then process the read data bit by bit.

wysota
1st October 2013, 08:08
QDataStream is not a general purpose binary stream, it is a serialization mechanism which expects additional data in the stream when reading from that stream. Use QFile::read() instead.