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 binary data to String
QtWS25 Last Chance

Converting binary data to String

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5serial portbinary format
12 Posts 4 Posters 2.9k Views
  • 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.
  • D Offline
    D Offline
    deleted286
    wrote on last edited by
    #1

    Hi everone. I have a huge binary data. I've read it on serial port. I want to convert it to string and see that datas on screen. How can i do it?

    void MainWindow::readData()
    {
        const QByteArray data = m_serial->readAll();
        m_console->putData(data);
        qDebug() << "reading" << data;
    
    }
    

    I've used the terminal example on qt.

    jsulmJ 1 Reply Last reply
    0
    • D deleted286

      Hi everone. I have a huge binary data. I've read it on serial port. I want to convert it to string and see that datas on screen. How can i do it?

      void MainWindow::readData()
      {
          const QByteArray data = m_serial->readAll();
          m_console->putData(data);
          qDebug() << "reading" << data;
      
      }
      

      I've used the terminal example on qt.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @suslucoder said in Converting binary data to String:

      How can i do it?

      This question can't be answered without knowing the binary format...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        How do you want to display it? A string of byte values (numbers)? Or hex? Binary string like 00101101011? Or you want to interpret the data as ANSI characters? Or UTF?

        With binary data, it can mean anything and be encoded in any way. It's impossible to guess what you need without more information about that data.

        If you want to display data as hex, this should help:

        const QByteArray data = m_serial->readAll().toHex();
        m_console->putData(data);
        qDebug() << "reading" << data;
        

        (Z(:^

        1 Reply Last reply
        3
        • jsulmJ jsulm

          @suslucoder said in Converting binary data to String:

          How can i do it?

          This question can't be answered without knowing the binary format...

          D Offline
          D Offline
          deleted286
          wrote on last edited by
          #4

          @jsulm Screenshot from 2021-02-23 10-22-27.png

          Here is the format of file

          I want to achieve int numbers like 452 or -65 etc.

          jsulmJ 1 Reply Last reply
          0
          • D deleted286

            @jsulm Screenshot from 2021-02-23 10-22-27.png

            Here is the format of file

            I want to achieve int numbers like 452 or -65 etc.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @suslucoder said in Converting binary data to String:

            Here is the format of file

            No, it's not! This is an example of the data.
            Do you have the format specification describing what it contains and how to interpret it?
            Could you at least tell us what the data actually contains? Numbers, strings, something else?
            Or how do you expect us to help you?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              Hi,

              This is not the file format, it's just a dump of it.

              A file format is the documentation of the organisation of the data inside the file.

              For example, the 4 first by might represent a magic number identifying the type of the file, then you have some headers, etc. That's what you need to know in order to make sense of your data. Beside that, since it's binary, you should rather avoid trying to just make a string out of it because you are likely going to hit null termination chars.

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

              jsulmJ D 2 Replies Last reply
              3
              • SGaistS SGaist

                Hi,

                This is not the file format, it's just a dump of it.

                A file format is the documentation of the organisation of the data inside the file.

                For example, the 4 first by might represent a magic number identifying the type of the file, then you have some headers, etc. That's what you need to know in order to make sense of your data. Beside that, since it's binary, you should rather avoid trying to just make a string out of it because you are likely going to hit null termination chars.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @SGaist said in Converting binary data to String:

                bull termination

                bull termination? :-)

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                SGaistS 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  This is not the file format, it's just a dump of it.

                  A file format is the documentation of the organisation of the data inside the file.

                  For example, the 4 first by might represent a magic number identifying the type of the file, then you have some headers, etc. That's what you need to know in order to make sense of your data. Beside that, since it's binary, you should rather avoid trying to just make a string out of it because you are likely going to hit null termination chars.

                  D Offline
                  D Offline
                  deleted286
                  wrote on last edited by
                  #8

                  @SGaist Sorry. I've understand now. I have a buffer which size is 10. I have 10 different interger values on it. Like Ax Ay Bx By ....

                  SGaistS 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @SGaist said in Converting binary data to String:

                    bull termination

                    bull termination? :-)

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @jsulm said in Converting binary data to String:

                    @SGaist said in Converting binary data to String:

                    bull termination

                    bull termination? :-)

                    The ones that gives you the horns when doing inappropriate QByteArray -> QString conversion :-D

                    Damn autocorrect, fixed :-)

                    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
                    2
                    • D deleted286

                      @SGaist Sorry. I've understand now. I have a buffer which size is 10. I have 10 different interger values on it. Like Ax Ay Bx By ....

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @suslucoder said in Converting binary data to String:

                      @SGaist Sorry. I've understand now. I have a buffer which size is 10. I have 10 different interger values on it. Like Ax Ay Bx By ....

                      Integers value may have different sizes, are they 32 or 64 bit ?
                      Once you know what exactly, you can split your binary data properly and convert to the appropriate representation.

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

                      D 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        @suslucoder said in Converting binary data to String:

                        @SGaist Sorry. I've understand now. I have a buffer which size is 10. I have 10 different interger values on it. Like Ax Ay Bx By ....

                        Integers value may have different sizes, are they 32 or 64 bit ?
                        Once you know what exactly, you can split your binary data properly and convert to the appropriate representation.

                        D Offline
                        D Offline
                        deleted286
                        wrote on last edited by
                        #11

                        @SGaist they are 16 bit

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

                          And that binary contains just that ?

                          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

                          • Login

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