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

Binary operation

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.3k 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.
  • jipe3001J Offline
    jipe3001J Offline
    jipe3001
    wrote on last edited by
    #1

    Hi everyone,

    I am facing the following issue:

    I am succesfully reading raw bytes from a Qserialport but cannot find how
    to manipulate these bytes on a binary basis.

    I tried several format from QBytearray to QDatastream but can never apply a
    binary operator (NOT,OR,AND) to the bytes received.

    Thks in advance for your coop,

    Jean-Pierre

    J.HilkJ jsulmJ 2 Replies Last reply
    0
    • jipe3001J Offline
      jipe3001J Offline
      jipe3001
      wrote on last edited by
      #8

      Thanks to both of you, it works perfectly,
      great support !!

      1 Reply Last reply
      0
      • jipe3001J jipe3001

        Hi everyone,

        I am facing the following issue:

        I am succesfully reading raw bytes from a Qserialport but cannot find how
        to manipulate these bytes on a binary basis.

        I tried several format from QBytearray to QDatastream but can never apply a
        binary operator (NOT,OR,AND) to the bytes received.

        Thks in advance for your coop,

        Jean-Pierre

        J.HilkJ Online
        J.HilkJ Online
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @jipe3001
        Hi,
        for Bitwise logic operation I would suggest QBitArray thats what it made for or, the good old std:bitset


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        jipe3001J 1 Reply Last reply
        0
        • jipe3001J jipe3001

          Hi everyone,

          I am facing the following issue:

          I am succesfully reading raw bytes from a Qserialport but cannot find how
          to manipulate these bytes on a binary basis.

          I tried several format from QBytearray to QDatastream but can never apply a
          binary operator (NOT,OR,AND) to the bytes received.

          Thks in advance for your coop,

          Jean-Pierre

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

          @jipe3001 Can you show your code? How did you try to apply binary operators?

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

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @jipe3001
            Hi,
            for Bitwise logic operation I would suggest QBitArray thats what it made for or, the good old std:bitset

            jipe3001J Offline
            jipe3001J Offline
            jipe3001
            wrote on last edited by
            #4

            @J.Hilk

            To make my request simpler:

            let's say I declare a variable value as follows:

            qint8 value;

            How can I manipulate this variable with binary operators ?

            1 Reply Last reply
            0
            • sneubertS Offline
              sneubertS Offline
              sneubert
              wrote on last edited by sneubert
              #5

              since qint8 is typedef for signed char, do you mean

              qint8 andVal = value & 0x000111;
              qint8 orVal = value | 0x10101010;
              qint8 notVal = ~value; 
              

              http://en.cppreference.com/w/cpp/language/operator_arithmetic

              jsulmJ 1 Reply Last reply
              4
              • sneubertS sneubert

                since qint8 is typedef for signed char, do you mean

                qint8 andVal = value & 0x000111;
                qint8 orVal = value | 0x10101010;
                qint8 notVal = ~value; 
                

                http://en.cppreference.com/w/cpp/language/operator_arithmetic

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

                @sneubert Be careful: and, or, not are keywords in C++! You cannot use them as names for variables.
                @jipe3001

                qint8 value = 0x00;
                value |= 0x01; // sets the lowest bit to 1
                value &= 0xFE; // sets lowest bit to 0
                value = ~value;
                

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

                sneubertS 1 Reply Last reply
                3
                • jsulmJ jsulm

                  @sneubert Be careful: and, or, not are keywords in C++! You cannot use them as names for variables.
                  @jipe3001

                  qint8 value = 0x00;
                  value |= 0x01; // sets the lowest bit to 1
                  value &= 0xFE; // sets lowest bit to 0
                  value = ~value;
                  
                  sneubertS Offline
                  sneubertS Offline
                  sneubert
                  wrote on last edited by
                  #7

                  @jsulm
                  sorry you a right, I tried to make the point clear

                  1 Reply Last reply
                  0
                  • jipe3001J Offline
                    jipe3001J Offline
                    jipe3001
                    wrote on last edited by
                    #8

                    Thanks to both of you, it works perfectly,
                    great support !!

                    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