
Originally Posted by
nagabathula
i am converting it from binary to Hexadecimal
No, you are not. Binary data is already hexadecimal. It's like you said "I'm converting my sentences from letters to words".
How can i pass the value of k as the index position for the QByteArray data; so that i can append only from the start of the frame.
Let me solve this one for you but promise you will learn what "hexadecimal", "binary" and "ascii" really means.
From what I understand you are trying to find some data beginning with 0x1A2C11000000. To do that you need to construct such a pattern - a binary pattern, not a textual one.
So here goes...
this is a text pattern:
QByteArray pattern("1A2C11000000");
To copy to clipboard, switch view to plain text mode
And this is a binary pattern:
QByteArray pattern("\x1A\x2C\x11\x00\x00\x00");
To copy to clipboard, switch view to plain text mode
Now use QByteArrayMatcher to find your byte array.
int pos = 0;
while((pos = matcher.indexIn(data, pos)) != -1) {
qDebug() << "pattern found at pos" << pos;
}
QByteArrayMatcher matcher(pattern);
int pos = 0;
while((pos = matcher.indexIn(data, pos)) != -1) {
qDebug() << "pattern found at pos" << pos;
}
To copy to clipboard, switch view to plain text mode
Note, you have to care about a situation when a chunk of data ends in the middle of the pattern.
Bookmarks