I'm supposed to write a code that can deserialize numbers that are received from another device using serial port (RS232) in the form of a QByteArray
without using bitwise operators. The QByteArray
can contain any length of data from a single item to more than 20 items or even more. Is this possible?
The solution I've come up with so far is:
int numelems = 0;
int exp = 0;
for(int i = tempba.size() - 1 ; i > -1 ; --i) {
numelems += (unsigned char)tempba.at(i) * pow(256, exp);
++exp;
}
where tempba
is a QByteArray
filled with data read from a serial port. Is this approach correct? where can it be failed? any better way to achieve this?