비트 왼쪽 시프트 연산자
왼쪽 피연산자 값은 오른쪽 피연산자가 지정한 비트 수만큼 왼쪽으로 이동합니다.
비트 오른쪽 시프트 연산자
왼쪽 피연산자 값은 오른쪽 피연산자가 지정한 비트 수만큼 오른쪽으로 이동합니다.
다음은 Bitwise 왼쪽 및 오른쪽 시프트 연산자 -
로 작업하는 방법을 보여주는 예입니다.예시
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a << 2; /* 240 = 1111 0000 */
Console.WriteLine("Value of c is {0}", c);
c = a >> 2; /* 15 = 0000 1111 */
Console.WriteLine("Value of c is {0}", c);
Console.ReadLine();
}
}
} 출력
Value of c is 240 Value of c is 15