Home > Back-end >  Why C variable moves to the right 32-bit or itself?
Why C variable moves to the right 32-bit or itself?

Time:09-18

Int main ()
{
Int z=0 x12345678;
cout Z=z & gt;> 32.
cout return 0;
}

The output
12345678
12345678


What reason is this?

CodePudding user response:

a> The value of b is a/2 ^ b take down the whole (in other words, a symbol of a moves to the right) are the moves to the right on the arithmetic,
You move the 32-bit, too big, the behavior is undefined standard

CodePudding user response:

Undefined behavior results meaningless
How much is don't tube the results
It is important to note left moves to the right can't greater than or equal to the number of digits

CodePudding user response:

Refer to https://docs.microsoft.com/zh-cn/cpp/cpp/left-shift-and-right-shift-operators-input-and-output? View=v - 2019

Additional Details
The result of a shift operation is undefined if i.e. The expression is negative or if additive - expression is greater than or equal to The number of bits in The (promoted) shift - expression. No shift operation is performed if additive - expression is 0.

If the number of shift is negative, or greater than or equal to the length of the data type, the result uncertain, int length for 32-bit here, so right 32-bit result not sure.

CodePudding user response:

This is implementing in x86/x64 processors, the movement of the shift instruction digits did mod word length processing (32 or mod mod 64) depending on the type of the operands, so moving 32-bit and 0 a is the same as

  • Related