Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Binary data in SerialPort
Qt 6.12 LTS is out! See what's new in the release blog

Binary data in SerialPort

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 6.7k 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.
  • Y Offline
    Y Offline
    yasinn
    wrote on last edited by
    #4

    sorry for adding but;
    when I send 00100101 data I saw "%" as ex, or
    when I send 00100110 data I saw "& " that symbol.

    How can I turn those symbol into binary

    aha_1980A 1 Reply Last reply
    0
    • Y yasinn

      sorry for adding but;
      when I send 00100101 data I saw "%" as ex, or
      when I send 00100110 data I saw "& " that symbol.

      How can I turn those symbol into binary

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #5

      @yasinn said in Binary data in SerialPort:

      sorry for adding but;
      when I send 00100101 data I saw "%" as ex, or
      when I send 00100110 data I saw "& " that symbol.

      How can I turn those symbol into binary

      Hello, the data is already binary, but you are interpreting them as ASCII characters (when you append the chars to a text edit).

      What do you actually want to do with the data you receive?

      Qt has to stay free or it will die.

      Y 1 Reply Last reply
      2
      • aha_1980A aha_1980

        @yasinn said in Binary data in SerialPort:

        sorry for adding but;
        when I send 00100101 data I saw "%" as ex, or
        when I send 00100110 data I saw "& " that symbol.

        How can I turn those symbol into binary

        Hello, the data is already binary, but you are interpreting them as ASCII characters (when you append the chars to a text edit).

        What do you actually want to do with the data you receive?

        Y Offline
        Y Offline
        yasinn
        wrote on last edited by
        #6

        @aha_1980
        firstly thanks for your reply, I send distance data in binary and I wanna read as decimal as result.
        for ex if I send 00000111 data , I wanna read 7.

        you said that " the data is already binary, but you are interpreting them as ASCII characters" , yes I know but how can I convert ıt into decimal ?

        aha_1980A 1 Reply Last reply
        0
        • Y yasinn

          @aha_1980
          firstly thanks for your reply, I send distance data in binary and I wanna read as decimal as result.
          for ex if I send 00000111 data , I wanna read 7.

          you said that " the data is already binary, but you are interpreting them as ASCII characters" , yes I know but how can I convert ıt into decimal ?

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by aha_1980
          #7

          @yasinn said in Binary data in SerialPort:

          @aha_1980
          firstly thanks for your reply, I send distance data in binary and I wanna read as decimal as result.
          for ex if I send 00000111 data , I wanna read 7.

          you said that " the data is already binary, but you are interpreting them as ASCII characters" , yes I know but how can I convert ıt into decimal ?

          There's no need to convert, the binary data 00000111 is already 7. The problem you might facing is, that each byte is stored as a char and usally these are used to encode text.

          Nevertheless, a char is an int and you can do arithmetics with it and compare it, etc.

          Qt has to stay free or it will die.

          Y 1 Reply Last reply
          2
          • Y Offline
            Y Offline
            yasinn
            wrote on last edited by
            #8
            This post is deleted!
            aha_1980A 1 Reply Last reply
            0
            • aha_1980A aha_1980

              @yasinn said in Binary data in SerialPort:

              @aha_1980
              firstly thanks for your reply, I send distance data in binary and I wanna read as decimal as result.
              for ex if I send 00000111 data , I wanna read 7.

              you said that " the data is already binary, but you are interpreting them as ASCII characters" , yes I know but how can I convert ıt into decimal ?

              There's no need to convert, the binary data 00000111 is already 7. The problem you might facing is, that each byte is stored as a char and usally these are used to encode text.

              Nevertheless, a char is an int and you can do arithmetics with it and compare it, etc.

              Y Offline
              Y Offline
              yasinn
              wrote on last edited by
              #9

              @aha_1980 said in Binary data in SerialPort:

              @yasinn said in Binary data in SerialPort:

              @aha_1980
              firstly thanks for your reply, I send distance data in binary and I wanna read as decimal as result.
              for ex if I send 00000111 data , I wanna read 7.

              you said that " the data is already binary, but you are interpreting them as ASCII characters" , yes I know but how can I convert ıt into decimal ?

              There's no need to convert, the binary data 00000111 is already 7. The problem you might facing is, that each byte is stored as a char and usally these are used to encode text.

              Nevertheless, a char is an int and you can do arithmetics with it and compare it, etc.

              thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

              Should I compare 255 characters for it ?

              1 Reply Last reply
              0
              • Y yasinn

                This post is deleted!

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @yasinn said in Binary data in SerialPort:

                thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

                I'm sorry, but it seems you should really learn basic C programming - you will stuck soon again otherwise.

                Given, that each byte you receive from the serial port is a distance in meters, you could do something like:

                const QByteArray data = serial.readAll();
                for (int i = 0; i < data.size(); ++i) {
                    QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                    ui->textEdit->append(text);
                }
                

                Qt has to stay free or it will die.

                Y 1 Reply Last reply
                3
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #11
                      QByteArray data= serial->readAll();
                      QString s_data;
                      for (char singleByte : data)
                          s_data.append(ui->textEdit->locale().toString(ststic_cast<qint16>(singleByte))); //if it's unsigned change qint16 to quint16
                      ui->textEdit->setText(s_data);
                  

                  "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
                  2
                  • aha_1980A aha_1980

                    @yasinn said in Binary data in SerialPort:

                    thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

                    I'm sorry, but it seems you should really learn basic C programming - you will stuck soon again otherwise.

                    Given, that each byte you receive from the serial port is a distance in meters, you could do something like:

                    const QByteArray data = serial.readAll();
                    for (int i = 0; i < data.size(); ++i) {
                        QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                        ui->textEdit->append(text);
                    }
                    
                    Y Offline
                    Y Offline
                    yasinn
                    wrote on last edited by
                    #12

                    @aha_1980 said in Binary data in SerialPort:

                    @yasinn said in Binary data in SerialPort:

                    thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

                    I'm sorry, but it seems you should really learn basic C programming - you will stuck soon again otherwise.

                    Given, that each byte you receive from the serial port is a distance in meters, you could do something like:

                    const QByteArray data = serial.readAll();
                    for (int i = 0; i < data.size(); ++i) {
                        QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                        ui->textEdit->append(text);
                    }
                    

                    Thank u so much. Sorry for my ignorance..

                    aha_1980A 2 Replies Last reply
                    1
                    • Y yasinn

                      @aha_1980 said in Binary data in SerialPort:

                      @yasinn said in Binary data in SerialPort:

                      thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

                      I'm sorry, but it seems you should really learn basic C programming - you will stuck soon again otherwise.

                      Given, that each byte you receive from the serial port is a distance in meters, you could do something like:

                      const QByteArray data = serial.readAll();
                      for (int i = 0; i < data.size(); ++i) {
                          QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                          ui->textEdit->append(text);
                      }
                      

                      Thank u so much. Sorry for my ignorance..

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @yasinn said in Binary data in SerialPort:

                      for (int i = 0; i < data.size(); ++i) {
                      QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                      ui->textEdit->append(text);
                      }

                      Thank u so much. Sorry for my ignorance..

                      Never mind! We all have started at the bottom... Good luck with your project.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      0
                      • Y yasinn

                        @aha_1980 said in Binary data in SerialPort:

                        @yasinn said in Binary data in SerialPort:

                        thaks for advice, but ı dont wanna do arithmatics with data, I just want to saw it as deciamal. I work on a radar project, I cant say "your target is 01010111 meters away from you " :)

                        I'm sorry, but it seems you should really learn basic C programming - you will stuck soon again otherwise.

                        Given, that each byte you receive from the serial port is a distance in meters, you could do something like:

                        const QByteArray data = serial.readAll();
                        for (int i = 0; i < data.size(); ++i) {
                            QString text = QObject::tr("The target is %1 meters away").arg(int(data.at(i)));
                            ui->textEdit->append(text);
                        }
                        

                        Thank u so much. Sorry for my ignorance..

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @yasinn

                        Thinking about the problem again, casting to uchar seems better so you also get the distances between 128 and 255 meters.

                        const QByteArray data = serial.readAll();
                        for (int i = 0; i < data.size(); ++i) {
                            QString text = QObject::tr("The target is %1 meters away").arg(uchar(data.at(i)));
                            ui->textEdit->append(text);
                        }
                        

                        Qt has to stay free or it will die.

                        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
                        • Unsolved