qt - Qbytearray byte to int and storing it as string value -
i want convert byte data stored in qbytearray string value. string value using displaying in ui window..
qbytearray array; array.append( 0x02 ); array.append( 0xc1); qdebug()<<( uint )array[0]<<" "<<( uint )array[1]; uint = 0x00000000; |= array[1]; qdebug()<<i; uint j = 0x00000000 | ( array[0] << 8 ); qdebug()<<j; |= j; bool b = false; qstring str = qstring::number( ); qdebug()<<str;
but str prints "4294967233"...this code works of bytes 0x1, 0x45 , of other..but code not working bytes of data string..please me , write code , post here..thanks
all values equal or bigger 0x80 interprets in sample negative values, need cast unsigned type before bitwise operations.
qbytearray array; array.append( 0x02 ); array.append( 0xc1); unsigned int value = 0; (int = 0; < array.size(); i++) value = (value << 8) | static_cast<unsigned char>(array[i]); qstring str = qstring::number(value); qdebug() << value << str;
Comments
Post a Comment