[SOLVED] convert binary number to qtint64
-
hi , i need to change this a 50bit number to qint64 but i always return 0
its my code :
@QString num = "11111111111111111111111111111111111111111111111111";
qint64 nn ;
bool ok;
nn = num.toLong(&ok , 2);
qDebug() << "nummmm " << nn;
@nn is 0 , why it cant cast this number to qint64 ?
ty -
Hi,
What does "ok" tells you ?
Is that a type ? nn is declared a qint32
-
ty for your answer
i changed nn type to qint64 but still nn is 0
ok is False[quote author="SGaist" date="1362046252"]Hi,
What does "ok" tells you ?
Is that a type ? nn is declared a qint32[/quote]
-
So it means the conversion fails.
With the code you gave, the conversion is successful, so are you sure the string you are using in your real code is valid for that conversion ?
-
yes this code is works fine with 1111111111111111111111111111111 and numbers smaller than this number (31 x 1 i mean ), but bigger than this number is fail ..
[quote author="SGaist" date="1362046837"]So it means the conversion fails.
With the code you gave, the conversion is successful, so are you sure the string you are using in your real code is valid for that conversion ?[/quote]
-
[quote author="Bepehr" date="1362046520"]
ok is False
[/quote]The conversion has failed. Check "QString::toLong documentation":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toLong:
bq. If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
Most probably your string is out of the range for long. You should try using "QString::toLongLong":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toLongLong which on success will return you "qlonglong":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qlonglong-typedef Btw qlonglong is the same as "qint64":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qint64-typedef.
-
ty , its works fine now ...
[quote author="leon.anavi" date="1362047405"][quote author="Bepehr" date="1362046520"]
ok is False
[/quote]The conversion has failed. Check "QString::toLong documentation":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toLong:
bq. If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.
Most probably your string is out of the range for long. You should try using "QString::toLongLong":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toLongLong which on success will return you "qlonglong":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qlonglong-typedef Btw qlonglong is the same as "qint64":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qint64-typedef.[/quote]
-
[quote author="Bepehr" date="1362050347"]ty , its works fine now ...[/quote]
Nice, so the issue was solved :)