Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] convert binary number to qtint64
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] convert binary number to qtint64

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bepehr
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What does "ok" tells you ?

      Is that a type ? nn is declared a qint32

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bepehr
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bepehr
            wrote on last edited by
            #5

            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]

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #6

              [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.

              http://anavi.org/

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bepehr
                wrote on last edited by
                #7

                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]

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #8

                  [quote author="Bepehr" date="1362050347"]ty , its works fine now ...[/quote]

                  Nice, so the issue was solved :)

                  http://anavi.org/

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved