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