Unsolved How we can add integers?
-
Hi everyone;
I code the following but got only one number after summing ;bool ok; qint32 decc =Rx_CF_read.toInt(&ok,16); qDebug()<<"RX LO:"<<decc; bool ook; qint32 dec = df.toInt(&ook,16); qDebug()<<"Detected:"<<dec; qint32 sum= decc + dec; qDebug()<<"sum is:"<<sum;
RX LO:2464999998
Detected:5145000
sum is:51450000thanks
-
@Wasee thats most certainly not the code/output you actually have.
because
2464999998 does not fit into an int32! it becomes -1829967298 -
You should check if 'ok' returns true - why do you pass it to toInt() but don't check it afterwards?
And your output does not match your code - toInt() will return 0 when the range does not fit so you can not get an output of
RX LO:2464999998
-
@J-Hilk @Christian-Ehrlicher ;
can we add these following strings "2464999999" and "51450000" if yes then how and no then how it is possible?
thanks -
@Wasee Did you see https://doc.qt.io/qt-5/qstring.html#toUInt or https://doc.qt.io/qt-5/qstring.html#toLongLong ?
You need to know the min/max values different integer types can represend... -
@jsulm hi;
I check you suggested but I am unable to add them.
thanks -
@Wasee said in How we can add integers?:
but I am unable to add them
Please be so kind and explain what you did and what does not work.
Or do you expect us to guess? -
@Wasee said in How we can add integers?:
RX LO:2464999998
2^32 4294967296 int(2^32) -2147483648 int(2464999998) -2147483648
Strange ....
[EDIT]
INT_MIN Minimum value for a variable of type int . -2147483648read.toInt(&ok,16);
Are you sure your string is in hexa ?