Int16 to QByteArray
-
Hi,
Out of curiosity, why not use QByteArray::number ?
-
Hi,
withqDebug() << QByteArray::number(id,16);
you will get the four characters "2113". So it depends on what you really need.
-Michael.@m.sue said in Int16 to QByteArray:
Hi,
withqDebug() << QByteArray::number(id,16);
you will get the four characters "2113". So it depends on what you really need.
-Michael.@SGaist
Yes I've tried that function but I'll send the byteArray with TCP to a micro controller after the transformation, so QByteArray::nummer or .setNum is not an option. -
@m.sue said in Int16 to QByteArray:
Hi,
withqDebug() << QByteArray::number(id,16);
you will get the four characters "2113". So it depends on what you really need.
-Michael.@SGaist
Yes I've tried that function but I'll send the byteArray with TCP to a micro controller after the transformation, so QByteArray::nummer or .setNum is not an option.Use
QDataStream
over the bytearray.qint32 whatever = 5; QByteArray data; QDataStream out(&data, QIODevice::WriteOnly); // By default is in big endian out << whatever;
-
Use
QDataStream
over the bytearray.qint32 whatever = 5; QByteArray data; QDataStream out(&data, QIODevice::WriteOnly); // By default is in big endian out << whatever;
@kshegunov Thanks, less code this way. But still x00!\x13 and not 0x00\0x21\0x13.
Is there a way to rewrite it to regular hex codes ? Or does every controller understand this notation ?
-
Hi
Will the micro controller also run Qt and be able to use QDataStream ? -
@kshegunov Thanks, less code this way. But still x00!\x13 and not 0x00\0x21\0x13.
Is there a way to rewrite it to regular hex codes ? Or does every controller understand this notation ?
!
and\0x21
are one and the same binary-wise, I don't understand the question, rewrite it to what? It already is\0x21
. -
@m-sue
I also got \x00\x00!\x13 on Windows, but didn't knew that '!' is the same as 0x21..Is there a way to rewrite it as 0x21 ?
Thanks!
@TomHoe said in Int16 to QByteArray:
didn't knew that '!' is the same as 0x21..
See http://www.ascii-code.com/
'!'
== 33 == 0x21 == 0b00100001@TomHoe said in Int16 to QByteArray:
Is there a way to rewrite it to regular hex codes ? Or does every controller understand this notation ?
Again,
'!'
== 33 == 0x21 == 0b00100001Those are different ways of displaying the same bytes. The controller does not see any "hex" or "notation"; it only sees the sequence of 0's and 1's.
I recommend you learn about how bits/bytes are stored in computer memory: http://statmath.wu.ac.at/courses/data-analysis/itdtHTML/node55.html