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++?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 729 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on 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.HilkJ 1 Reply Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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.

      Ramkumar MohanR 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

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

        Ramkumar MohanR Offline
        Ramkumar MohanR Offline
        Ramkumar Mohan
        wrote on 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" ";

        JonBJ 1 Reply Last reply
        0
        • Ramkumar MohanR Ramkumar Mohan

          @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" ";

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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....

          Ramkumar MohanR 1 Reply Last reply
          1
          • JonBJ JonB

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

            Ramkumar MohanR Offline
            Ramkumar MohanR Offline
            Ramkumar Mohan
            wrote on 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.

            Christian EhrlicherC 1 Reply Last reply
            0
            • Ramkumar MohanR Ramkumar Mohan

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

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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

              Ramkumar MohanR 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

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

                Ramkumar MohanR Offline
                Ramkumar MohanR Offline
                Ramkumar Mohan
                wrote on 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 .

                Christian EhrlicherC 1 Reply Last reply
                0
                • Ramkumar MohanR Ramkumar Mohan

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

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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