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. Converting big number to base 24
Qt 6.11 is out! See what's new in the release blog

Converting big number to base 24

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 2.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.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by
    #1

    I want to display array of 20 bytes as a number with base 24. Can Qt do this conversion?

    Ni.SumiN 1 Reply Last reply
    0
    • M MartinD

      I want to display array of 20 bytes as a number with base 24. Can Qt do this conversion?

      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      @MartinD

      yes, it possible in Qt. int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const

      http://doc.qt.io/qt-5/qstring.html#toInt

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MartinD
        wrote on last edited by
        #3

        My big number has 160 bits. QString.toInt can't handle it.

        Ni.SumiN 1 Reply Last reply
        0
        • M MartinD

          My big number has 160 bits. QString.toInt can't handle it.

          Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by
          #4

          @MartinD

          you can use ::ToULongLong , ::toULong ..

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MartinD
            wrote on last edited by
            #5

            Still only 64 bits...

            kshegunovK 1 Reply Last reply
            0
            • M MartinD

              Still only 64 bits...

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @MartinD
              Hi,
              It's very basic math:

              BigIntType x;
              QString number;
              
              while (x != 0)  {
                  char reminder = x % 24;
                  x /= 24;
              
                  number += reminder < 10 ? '0' + reminder : 'A' + reminder - 10;
              }
              
              std::reverse(number.begin(), number.end());
              

              Your number system is bad, chose one that's a power of 2, so you can skip the divisions and use bit-wise operations instead.

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              3
              • M Offline
                M Offline
                MartinD
                wrote on last edited by
                #7

                I used the class in http://stackoverflow.com/questions/4735622/convert-large-hex-string-to-decimal-string . Nice code, easy to implement base 24 conversions.

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  Boost multiprecision is probably the most ready available bignum library you could use for this task. just use cpp_int as BigIntType in @kshegunov 's algorithm

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  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