Unsolved Parsing a hexadecimal data and calculating checksum
-
Hello, I want to first parse a hexadecimal data coming from a device, then calculate the checksum, convert the data to decimal and print it on my screen.
How can ı do that? -
@Rumeysa_135 Use https://doc.qt.io/qt-6/qstring.html#toInt to convert a string containing a hex number to an integer.
Don't know what kind of checksum you need.
"print it on my screen" - can be done using many widgets like QWidget, QTextEdit, ... - depends on how you want to show the data. -
@Rumeysa_135 How is this thread different to your older one: https://forum.qt.io/topic/142574/how-do-i-parse-string-arrays-in-qt ?
You already got some answers there... -
This post is deleted! -
@Rumeysa_135 said in Parsing a hexadecimal data and calculating checksum:
How can I integrate these two codes together?
I don't understand the question.
What do you mean with "integrate"?
Simply call the code where needed. -
@jsulm said in Parsing a hexadecimal data and calculating checksum:
I don't understand the question.
I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"
-
@J-Hilk I think byteArrayToUint32 is supposed to do that?
-
@jsulm nope, it just exists when the size doesn't match
auto count = bytes.size(); if (count == 0 || count > 4) { return 0; }
-
@J-Hilk said in Parsing a hexadecimal data and calculating checksum:
I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"
@jsulm nope, it just exists when the size doesn't match
So if you want to access 4 bytes (
sizeof(int32)
) for conversion use QByteArray QByteArray::mid(qsizetype pos, qsizetype len = -1) const. Otherwise if you want it to appear as an array ofint32
(and you know byte ordering is correct) usereinterpret_cast<>
to int array on the data.