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 use Arithmetic Operators with HexaDecimal Value in c++?
Forum Updated to NodeBB v4.3 + New Features

How to use Arithmetic Operators with HexaDecimal Value in c++?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 860 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.
  • R Offline
    R Offline
    Ramkumar Mohan
    wrote on 31 Oct 2022, 05:35 last edited by
    #1

    I am writing C++ code in QT and on how to use arithmetic operators with hexadecimal values.
    For example,

    1. 4D + 1 = 4E
      
    2. 4E - 1 = 4D
      
    J 1 Reply Last reply 31 Oct 2022, 06:31
    0
    • R Ramkumar Mohan
      31 Oct 2022, 05:35

      I am writing C++ code in QT and on how to use arithmetic operators with hexadecimal values.
      For example,

      1. 4D + 1 = 4E
        
      2. 4E - 1 = 4D
        
      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 31 Oct 2022, 06:31 last edited by
      #2

      @Ramkumar-Mohan the question is, where are these "HexaDecimal" values ? in your SourceCode ? than:

      0x4D + 1
      

      in strings you have stored ? convert them to ints and add them than:

      myString.toInt(nullptr, 16) + 1
      

      Anywhere else ? Then you should rethink your case, because there are no HexaDecimal values that a program works with.


      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.

      R 1 Reply Last reply 31 Oct 2022, 18:11
      2
      • J J.Hilk
        31 Oct 2022, 06:31

        @Ramkumar-Mohan the question is, where are these "HexaDecimal" values ? in your SourceCode ? than:

        0x4D + 1
        

        in strings you have stored ? convert them to ints and add them than:

        myString.toInt(nullptr, 16) + 1
        

        Anywhere else ? Then you should rethink your case, because there are no HexaDecimal values that a program works with.

        R Offline
        R Offline
        Ramkumar Mohan
        wrote on 31 Oct 2022, 18:11 last edited by Ramkumar Mohan
        #3

        @J-Hilk @JonB

                ba[0]=0x4D;
                qDebug()<<hex<<ba[0]+1;
        

        where, 4D is the hexadecimal value.

        I have put the Hexadecimal value in QString .

        code :
        QString element1=list_str2.at(0).toLocal8Bit().constData();

        element1 has "4D" value .

        How to use string value in it. ba[0]=0x" ";

        J 1 Reply Last reply 31 Oct 2022, 18:25
        0
        • R Ramkumar Mohan
          31 Oct 2022, 18:11

          @J-Hilk @JonB

                  ba[0]=0x4D;
                  qDebug()<<hex<<ba[0]+1;
          

          where, 4D is the hexadecimal value.

          I have put the Hexadecimal value in QString .

          code :
          QString element1=list_str2.at(0).toLocal8Bit().constData();

          element1 has "4D" value .

          How to use string value in it. ba[0]=0x" ";

          J Online
          J Online
          JonB
          wrote on 31 Oct 2022, 18:25 last edited by
          #4

          @Ramkumar-Mohan said in How to use Arithmetic Operators with HexaDecimal Value in c++?:

          How to use string value in it. ba[0]=0x" ";

          What does this mean? If you want ba to hold strings it needs to be a QVector<QString> or QStringList or a C++ array of QStrings. But then it won't hold numbers....

          R 1 Reply Last reply 31 Oct 2022, 18:29
          1
          • J JonB
            31 Oct 2022, 18:25

            @Ramkumar-Mohan said in How to use Arithmetic Operators with HexaDecimal Value in c++?:

            How to use string value in it. ba[0]=0x" ";

            What does this mean? If you want ba to hold strings it needs to be a QVector<QString> or QStringList or a C++ array of QStrings. But then it won't hold numbers....

            R Offline
            R Offline
            Ramkumar Mohan
            wrote on 31 Oct 2022, 18:29 last edited by
            #5

            @JonB

            How to use string value in it. ba[0]=0x" ";

            That means ,

            QByteArray ba(1);

            ba[0]= 0x 4D ;

            4d is the hexadecimal value.

            C 1 Reply Last reply 31 Oct 2022, 18:39
            0
            • R Ramkumar Mohan
              31 Oct 2022, 18:29

              @JonB

              How to use string value in it. ba[0]=0x" ";

              That means ,

              QByteArray ba(1);

              ba[0]= 0x 4D ;

              4d is the hexadecimal value.

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 31 Oct 2022, 18:39 last edited by
              #6

              @Ramkumar-Mohan said in How to use Arithmetic Operators with HexaDecimal Value in c++?:

              4d is the hexadecimal value.

              So what's wrong with

              ba[0] = 0x4d

              then?

              and what has this to do with Qt rather than basic c stuff?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              R 1 Reply Last reply 31 Oct 2022, 18:51
              0
              • C Christian Ehrlicher
                31 Oct 2022, 18:39

                @Ramkumar-Mohan said in How to use Arithmetic Operators with HexaDecimal Value in c++?:

                4d is the hexadecimal value.

                So what's wrong with

                ba[0] = 0x4d

                then?

                and what has this to do with Qt rather than basic c stuff?

                R Offline
                R Offline
                Ramkumar Mohan
                wrote on 31 Oct 2022, 18:51 last edited by
                #7

                @Christian-Ehrlicher

                i already convert hexadecimal value from string

                String val = MB

                HexaDecimal val = 4D 42

                and , we want arithmetic opertors with Hexadecimal value ,

                Example ,

                QByteArray ba[2];
                ba[0]= 0x4D;
                ba[1]= 0x42;

                qDebug()<<Hex<<ba[0]+ 1<<ba[1]+2;

                output:-

                4E 44

                It comes if you type the 4D value manually and use it. I have put that 4D hex value in string list how to use 4D data (0x4D) in string list here.
                i have no idea .

                C 1 Reply Last reply 31 Oct 2022, 18:55
                0
                • R Ramkumar Mohan
                  31 Oct 2022, 18:51

                  @Christian-Ehrlicher

                  i already convert hexadecimal value from string

                  String val = MB

                  HexaDecimal val = 4D 42

                  and , we want arithmetic opertors with Hexadecimal value ,

                  Example ,

                  QByteArray ba[2];
                  ba[0]= 0x4D;
                  ba[1]= 0x42;

                  qDebug()<<Hex<<ba[0]+ 1<<ba[1]+2;

                  output:-

                  4E 44

                  It comes if you type the 4D value manually and use it. I have put that 4D hex value in string list how to use 4D data (0x4D) in string list here.
                  i have no idea .

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 31 Oct 2022, 18:55 last edited by
                  #8

                  @Ramkumar-Mohan said in How to use Arithmetic Operators with HexaDecimal Value in c++?:

                  It comes if you type the 4D value manually and use it. I have put that 4D hex value in string list how to use 4D data (0x4D) in string list here.
                  i have no idea .

                  And I've not a single idea what you want to do and where your problem is.

                  Please properly describe what you want to do (and with what) and where your problem is.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2

                  1/8

                  31 Oct 2022, 05:35

                  • Login

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