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
Forum Updated to NodeBB v4.3 + New Features

Converting binary data to String

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5serial portbinary format
12 Posts 4 Posters 3.0k Views 2 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.
  • S Offline
    S Offline
    sierdzio
    Moderators
    wrote on 23 Feb 2021, 07:17 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
    • J jsulm
      23 Feb 2021, 07:16

      @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 23 Feb 2021, 07:24 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.

      J 1 Reply Last reply 23 Feb 2021, 07:26
      0
      • D deleted286
        23 Feb 2021, 07:24

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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 23 Feb 2021, 07:26 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Feb 2021, 07:27 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

          J D 2 Replies Last reply 23 Feb 2021, 07:28
          3
          • S SGaist
            23 Feb 2021, 07:27

            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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 23 Feb 2021, 07:28 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

            S 1 Reply Last reply 23 Feb 2021, 07:38
            1
            • S SGaist
              23 Feb 2021, 07:27

              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 23 Feb 2021, 07:30 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 ....

              S 1 Reply Last reply 23 Feb 2021, 07:39
              0
              • J jsulm
                23 Feb 2021, 07:28

                @SGaist said in Converting binary data to String:

                bull termination

                bull termination? :-)

                S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 23 Feb 2021, 07:38 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
                  23 Feb 2021, 07:30

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

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 23 Feb 2021, 07:39 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 23 Feb 2021, 07:43
                  1
                  • S SGaist
                    23 Feb 2021, 07:39

                    @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 23 Feb 2021, 07:43 last edited by
                    #11

                    @SGaist they are 16 bit

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 23 Feb 2021, 11:47 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

                      12/12

                      23 Feb 2021, 11:47

                      • Login

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