// << : 왼쪽 시프트 : 비트당 2배(2의 배수배)
// >> : 오른쪽 시프트 : 비트당 1/2배
using System;

public class 시프트연산자
{
    public static void Main()
    {
        int num = 0;
        int result = 0;

        num = 2; // 4배
        result = num << 2; // 왼쪽으로 비트를 2칸 이동
        Console.WriteLine("{0}", result); // 8

        num = 40; // 1/4배
        result = num >> 2; // 오른쪽으로 2칸 이동
        Console.WriteLine("{0}", result); // 10
    }
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

14. 배수의 합 구하는 프로그램(while문 / do ~ while문 사용)  (0) 2009.08.04
13. 비트연산자  (0) 2009.08.04
11. 짝수의 합 구하는 프로그램  (0) 2009.08.04
10. 상수  (0) 2009.08.04
9. 변수  (0) 2009.08.04
Posted by holland14
: