c++ - Qt5 convert chars to 8bits unsigned values -


i have 2 ways used convert characters representing 8bit byte values. in first 1 gives correct answer in second gives 0 had ba.size()-1. question why have in second one? know /0 terminator. if im not wrong? there better way this?

    // simple test if can take bytes , them in decimal (0-255)format:     qbytearray ba("down came glitches , burnt in ditches , slept after ate our dead...");     (int = 0; < ba.size(); ++i)     qdebug() << "bytes are: "<< static_cast<quint8>(ba[i]);     // simple second way it...     int j = 0;     while (j < ba.size()-1){     qdebug() << "bytes are: "<< static_cast<quint8>(ba[++j]); } 

the difference because of invalid use of increment operation. when use ++j has value 1, never 0 index. last index bigger array size. right way is:

qdebug() << "bytes are: "<< static_cast<quint8>(ba[j++]); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -