How to use Arithmetic Operators with HexaDecimal Value in c++?
-
wrote on 31 Oct 2022, 05:35 last edited by
I am writing C++ code in QT and on how to use arithmetic operators with hexadecimal values.
For example,-
4D + 1 = 4E
-
4E - 1 = 4D
-
-
I am writing C++ code in QT and on how to use arithmetic operators with hexadecimal values.
For example,-
4D + 1 = 4E
-
4E - 1 = 4D
@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-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.
wrote on 31 Oct 2022, 18:11 last edited by 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" ";
-
@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" ";
wrote on 31 Oct 2022, 18:25 last edited by@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 aQVector<QString>
orQStringList
or a C++ array ofQString
s. But then it won't hold numbers.... -
@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 aQVector<QString>
orQStringList
or a C++ array ofQString
s. But then it won't hold numbers....wrote on 31 Oct 2022, 18:29 last edited byHow to use string value in it. ba[0]=0x" ";
That means ,
QByteArray ba(1);
ba[0]= 0x 4D ;
4d is the hexadecimal value.
-
How to use string value in it. ba[0]=0x" ";
That means ,
QByteArray ba(1);
ba[0]= 0x 4D ;
4d is the hexadecimal value.
@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-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?
wrote on 31 Oct 2022, 18:51 last edited byi 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 . -
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 .@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.
1/8