For efficiency you can use some bit operators to extract bits from int, but since you have/need just one string and you don't need that many conversions, basically you can do this with just one conversion from that int to a QString, i think it is not really necessary to "play" with bits //unless you are programming for some embedded system with small amount of memory
The code in tbscope post doesn't work, but you don't really need to convert the QChar into int again, you can compare what operator[] returns with the character '0' or '1', something like:
QString str
("010100");
//you have the string with 1 and 0 if(str[0] == '0') // you test the first character if it is character '0'
qDebug() << "first character in the string is zero"; //call the function you need
QString str("010100"); //you have the string with 1 and 0
if(str[0] == '0') // you test the first character if it is character '0'
qDebug() << "first character in the string is zero"; //call the function you need
To copy to clipboard, switch view to plain text mode
you can do it in a loop, or whatever fit your needs
LE: if you really need the integer back see the link in my first post, also if you don't like the QString approach you can search the Qt documentation for some container for bits (something more or less equivalent for std::bitset) it might be easier to use than bit operators.
Bookmarks