移位運算符優先級低於加減

 今天調試了半天代碼,弄得我都快懷疑人生了,最後發現是移位運算符優先級的問題,以前一直以爲移位的優先級較高,實踐發現移位運算符優先級低於加減的!!!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            byte x = 0x20;

            Console.WriteLine((int)(x & 0xf0) << 4 + 2 );

            Console.ReadLine();
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章