Converting binary data to String
-
Hi everone. I have a huge binary data. I've read it on serial port. I want to convert it to string and see that datas on screen. How can i do it?
void MainWindow::readData() { const QByteArray data = m_serial->readAll(); m_console->putData(data); qDebug() << "reading" << data; }
I've used the terminal example on qt.
-
@suslucoder said in Converting binary data to String:
How can i do it?
This question can't be answered without knowing the binary format...
-
How do you want to display it? A string of byte values (numbers)? Or hex? Binary string like
00101101011
? Or you want to interpret the data as ANSI characters? Or UTF?With binary data, it can mean anything and be encoded in any way. It's impossible to guess what you need without more information about that data.
If you want to display data as hex, this should help:
const QByteArray data = m_serial->readAll().toHex(); m_console->putData(data); qDebug() << "reading" << data;
-
@suslucoder said in Converting binary data to String:
Here is the format of file
No, it's not! This is an example of the data.
Do you have the format specification describing what it contains and how to interpret it?
Could you at least tell us what the data actually contains? Numbers, strings, something else?
Or how do you expect us to help you? -
Hi,
This is not the file format, it's just a dump of it.
A file format is the documentation of the organisation of the data inside the file.
For example, the 4 first by might represent a magic number identifying the type of the file, then you have some headers, etc. That's what you need to know in order to make sense of your data. Beside that, since it's binary, you should rather avoid trying to just make a string out of it because you are likely going to hit null termination chars.
-
-
@jsulm said in Converting binary data to String:
@SGaist said in Converting binary data to String:
bull termination
bull termination? :-)
The ones that gives you the horns when doing inappropriate QByteArray -> QString conversion :-D
Damn autocorrect, fixed :-)
-
@suslucoder said in Converting binary data to String:
@SGaist Sorry. I've understand now. I have a buffer which size is 10. I have 10 different interger values on it. Like Ax Ay Bx By ....
Integers value may have different sizes, are they 32 or 64 bit ?
Once you know what exactly, you can split your binary data properly and convert to the appropriate representation. -
And that binary contains just that ?