Unsolved BIt Shift Error
-
Hi all ,
i am developing an application where i need to shift the bit values .
quint64 bit_values; int num=1; bit_values = num<<42;
So the output of bit_values is 1024. This output is wrong .the correct output must be 4398046511104 . After analysing i came to know that . QT Compiler is of 32bit .
I tried to split 64bit values to two 32 bit values . but it failing . Please help me to resolve this issue
Thanks
-
@akshay123 num is an int (32bit) that is the problem: you're shifting a 32bit int by 42 positions, this causes an overflow. Change num to quint64 and it will work.
Note: there is no such thing as "Qt compiler".
-
Thanks @jsulm . As you have specifed i have changed it to uint64 . now tried to shift the values . but the result is same
-
@akshay123 I tried and it works:
quint64 bit_values; quint64 num = 1; bit_values = num<<42; qDebug() << bit_values;
Can you show your code?
-
QList<quint64> temp_Shifted_values; quint64 tempValue=0; quint64 megaValue=0; for(int i=0; i< bit_Value.count(); i++) //bit values is a function parameter { tempValue = bit_Value.at(i) << bit_Low_Value.at(i); temp_Shifted_values.append(tempValue); } for(int i=0; i< temp_Shifted_values.count(); i++) { megaValue = megaValue | temp_Shifted_values.at(i); }
i am using ```
qt-opensource-windows-x86-mingw48_opengl-5.2.1 -
@akshay123 What is the type of bit_Value ?
-
the type of bit value is int
-
@akshay123 So, you again do the same mistake: int is 32bit
-
@jsulm Thanks . Sorry for the that . Since code size is very big . i didnt noticed . Thanks for your help