# << 運算子 (C# 參考)<< operator (C# Reference)

``````uint x = 0b_1100_1001_0000_0000_0000_0000_0001_0001;
Console.WriteLine(\$"Before: {Convert.ToString(x, toBase: 2)}");

uint y = x << 4;
Console.WriteLine(\$"After:  {Convert.ToString(y, toBase: 2)}");
// Output:
// Before: 11001001000000000000000000010001
// After:  10010000000000000000000100010000
``````

## 位移計數Shift count

• `x` 的型別為 intuint，則位移計數是由第二個運算元的低位五個位元所給定。If the type of `x` is int or uint, the shift count is given by the low-order five bits of the second operand. 也就是說，位移計數是從 `count & 0x1F` (或 `count & 0b_1_1111`) 所計算。That is, the shift count is computed from `count & 0x1F` (or `count & 0b_1_1111`).

• `x` 的型別為 longulong，則位移計數是由第二個運算元的低位六個位元所給定。If the type of `x` is long or ulong, the shift count is given by the low-order six bits of the second operand. 也就是說，位移計數是從 `count & 0x3F` (或 `count & 0b_11_1111`) 所計算。That is, the shift count is computed from `count & 0x3F` (or `count & 0b_11_1111`).

``````int a = 0b_0001;
int count1 = 0b_0000_0001;
int count2 = 0b_1110_0001;
Console.WriteLine(\$"{a} << {count1} is {a << count1}; {a} << {count2} is {a << count2}");
// Output:
// 1 << 1 is 2; 1 << 225 is 2
``````