Understand the shift operator

前端 未结 4 1578
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 17:21

I can not understand this shift operator (c# reference):

class MainClass1
{
 static void Main()
    {
        int i = 1;
        long lg = 1;
        Console         


        
4条回答
  •  醉酒成梦
    2020-12-03 17:37

    "The shift operator is essentially "mod" the width of the data."

    Rubbish! If the amount of the shift is greater than, or equal to, the width of the data, the result is undefined. Do not expect the same 'mod' operation that you happen to have seen, to happen with different compilers, or different versions of the same compiler, or in different shift situations in the same program, or when anything else changes. That's what 'undefined' means.

提交回复
热议问题