Please explain CVI question #335358: using the operator of bit-shift twice on the same line of code produces incorrect results

Hello

I just stumbled on http://www.ni.com/white-paper/12323/en#335358_by_Category.

With the help of the bit-shift operator twice on the same line of code produces incorrect results.
Workaround: Separate the operations of shift of two bits in two distinct lines of code.

Reported Version: 9.0    Solved Version: N/A    Added the: 14/02/2012

Could someone please explain what kind of construction causes such a question?

I have not noticed problems again and not have not noticed or found a thread about it.

Thank you.

The reported scenario looks like this:

unsigned int a = 1, b = 62;
unsigned  long long result = 1ULL << a << b;

The problem arises because of the temporary variable used when do two little is placed in the same line. This separation into two lines will produce correct results:

unsigned int a = 1, b = 62;
unsigned  long long result = 1ULL << a;
result = result << b;

Tags: NI Software

Similar Questions

Maybe you are looking for