Summary
1、Qt in QByteArray Store hexadecimal numbers ( for example 0xff), In fact, it is based on ASCII Code stored , The storage form is '\xff'( among \ It's a transcoding identifier ), Unit is byte ( A byte stores a hexadecimal number ) If you need to compare , use array.at(0) == '\xff' Express , instead of array.at(0) == 0xff .
2、 Judge QByteArray What's in it is int Integers , Or characters 'f': If it is int Integers , Then use int perhaps hex To judge , If it's a character ‘f’ , Then use ‘f’ To judge .
- such as QByteArray The content is ff , namely QByteArray[0] = f,QByteArray[1] = f, be QByteArray There are two characters stored ‘f’, Not integers 255.
- such as QByteArray The content is ff , namely QByteArray[0] = ff, be QByteArray It stores an integer 255, Not two characters ‘ff’.
notes : stay QByteArray in \xff And 0xff It's equivalent .
Hexadecimal conversion ( Commonly used in serial port and network communication )
int dec = 14 ;