Hi,
I have hex QString value 07 I need to convert it to binary, it should be 00000111, but I can only convert it to 111 (without 0), I made loop to to check values. I will need to find out how many 1 I have and use this bits as a mask, for example 11100100
1 - do something
1 - do something
1 - do something
0 - do nothing
0 - do nothing
1 - do something
0 - do nothing
0 - do nothing
My code works, But I get many warning and I guess, there is easier and more efficient way of doing this.
bool ok;
gmeMask
=QByteArray::number(str.
toLongLong(&ok,
16),
2);
qDebug
()<<
QByteArray::number(str.
toLongLong(&ok,
16),
2);
for (int i=7; i>=0 ; i--)
{
if (i<gmeMask.size())
{
if(i==7||gmeMask[i]==1) qDebug()<< "gmeMask1"<<i << gmeMask[i];
if(i==6||gmeMask[i]==1) qDebug()<< "gmeMask2"<<i << gmeMask[i];
if(i==5||gmeMask[i]==1) qDebug()<< "gmeMask3"<<i << gmeMask[i];
if(i==4||gmeMask[i]==1) qDebug()<< "gmeMask4"<<i << gmeMask[i];
if(i==3||gmeMask[i]==1) qDebug()<< "gmeMask5"<<i << gmeMask[i];
if(i==2||gmeMask[i]==1) qDebug()<< "gmeMask6"<<i << gmeMask[i];
if(i==1||gmeMask[i]==1) qDebug()<< "gmeMask7"<<i << gmeMask[i];
if(i==0||gmeMask[i]==1) qDebug()<< "gmeMask8"<<i << gmeMask[i];
}
}
QString str("07");
QByteArray gmeMask;
bool ok;
gmeMask=QByteArray::number(str.toLongLong(&ok,16),2);
qDebug()<< QByteArray::number(str.toLongLong(&ok,16),2);
for (int i=7; i>=0 ; i--)
{
if (i<gmeMask.size())
{
if(i==7||gmeMask[i]==1) qDebug()<< "gmeMask1"<<i << gmeMask[i];
if(i==6||gmeMask[i]==1) qDebug()<< "gmeMask2"<<i << gmeMask[i];
if(i==5||gmeMask[i]==1) qDebug()<< "gmeMask3"<<i << gmeMask[i];
if(i==4||gmeMask[i]==1) qDebug()<< "gmeMask4"<<i << gmeMask[i];
if(i==3||gmeMask[i]==1) qDebug()<< "gmeMask5"<<i << gmeMask[i];
if(i==2||gmeMask[i]==1) qDebug()<< "gmeMask6"<<i << gmeMask[i];
if(i==1||gmeMask[i]==1) qDebug()<< "gmeMask7"<<i << gmeMask[i];
if(i==0||gmeMask[i]==1) qDebug()<< "gmeMask8"<<i << gmeMask[i];
}
}
To copy to clipboard, switch view to plain text mode
Results
"111"
gmeMask6 2 1
gmeMask7 1 1
gmeMask8 0 1
Warning messages
..\bitai\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
..\bitai\mainwindow.cpp:22: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:22: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:23: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:23: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:24: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:24: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:25: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:25: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:26: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:26: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:27: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:27: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:28: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:28: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:29: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:29: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
..\bitai\mainwindow.cpp:22: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:22: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:23: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:23: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:24: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:24: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:25: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:25: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:26: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:26: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:27: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:27: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:28: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:28: note: candidate 2: operator==(int, int) <built-in>
..\bitai\mainwindow.cpp:29: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
c:\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qbytearray.h:456: note: candidate 1: bool QByteRef::operator==(char) const
..\bitai\mainwindow.cpp:29: note: candidate 2: operator==(int, int) <built-in>
To copy to clipboard, switch view to plain text mode
Bookmarks