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. How to change the byte order of a boost::multiprecision::cpp_int and store in a QByteArry
Qt 6.11 is out! See what's new in the release blog

How to change the byte order of a boost::multiprecision::cpp_int and store in a QByteArry

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 995 Views 3 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.
  • I Offline
    I Offline
    Infinity
    wrote on last edited by
    #1

    I have to change the byte order of a boost::multiprecision::cpp_int and store it in a QByteArry.

    That is how I do it for quint64:

    QByteArray MyLongNumber::intToByteArray(QDataStream::ByteOrder byteOrder)
    {
        // Convert the int to bianry QByteArray according to byteOrder (QDataStream::BigEndian | QDataStream::LittleEndian)
    
        QByteArray intByteArray;
        QDataStream intDataStream(&intByteArray, QIODevice::WriteOnly);
    
        intDataStream.setByteOrder(byteOrder);
        intDataStream << m_intNumber;
    
        return intByteArray;
    }
    

    How can I do it for a boost::multiprecision::cpp_int. I tried it like this:

    QByteArray MyBigNumber::cppIntToByteArray(QDataStream::ByteOrder byteOrder)
    {
        // Convert the int to bianry QByteArray according to byteOrder (QDataStream::BigEndian | QDataStream::LittleEndian)
    
        boost::multiprecision::cpp_int m_cppInt(4000000000000000);
    
        QByteArray intByteArray;
        QDataStream intDataStream(&intByteArray, QIODevice::WriteOnly);
    
        intDataStream.setByteOrder(byteOrder);
        intDataStream << m_cppInt;
    
        return intByteArray;
    }
    

    But that doesn't work. How can I do that?

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

      Hi,

      In what does it not work ?
      On what OS ?
      With which compiler ?

      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
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        How/why would QDataStream know anything about boost::multiprecision?

        They are from different frameworks, so unless the intDataStream is taught how to handle
        intDataStream << m_cppInt
        the operation is going to be undefined. I think you'll need to look under the hood to see how boost stores its mutliprecision types before making any assumptions about compatibility with Qt.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        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