JAVA/예제

[JAVA] ch03-22. 쉬프트 연산자

밍글링글링 2017. 8. 21.
728x90
 
public class Ex22 { // 쉬프트 연산자
    public static void main(String[] args){
        int temp;
        System.out.println(-8);
        System.out.println(Integer.toBinaryString(-8));
        System.out.println();
        
        temp = -8 << 1; // -8*2
        System.out.println("-8 << 1 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();
        
        temp = -8 << 2; // -8*4
        System.out.println("-8 << 2 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();

        System.out.println();
        System.out.println(-8);
        System.out.println(Integer.toBinaryString(-8));
        System.out.println();
        
        temp = -8 >> 1; // -8/2
        System.out.println("-8 >> 1 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();
        
        temp = -8 >> 2; // -8/4
        System.out.println("-8 >> 2 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();
        
        temp = -8 >>> 1; // -8*2
        System.out.println("-8 >>> 1 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();
        
        temp = -8 >>> 2; // -8*2
        System.out.println("-8 >>> 2 = " + temp);
        System.out.println(Integer.toBinaryString(temp));
        System.out.println();
    }
}

728x90

'JAVA > 예제' 카테고리의 다른 글

[JAVA] ch03-24. 실수형 강제형변환  (0) 2017.08.21
[JAVA] ch03-23. 비교 연산자  (0) 2017.08.21
[JAVA] ch03-21. 나머지값  (0) 2017.08.21
[JAVA] ch03-20. 3의 배수 출력  (0) 2017.08.21
[JAVA] ch03-19. 나눗셈과 나머지  (0) 2017.08.21

댓글