비트 연산자


Bitwise and Bit Shift Operators (비트 연산자)


~       Unary bitwise complement
<<      Signed left shift
>>      Signed right shift
>>>     Unsigned right shift
&       Bitwise AND
^       Bitwise exclusive OR
|       Bitwise inclusive OR


연산자 "<<", ">>"에 따라 x2, /2가 됩니다.

비트연산자에 따라 연산방법은 아주아주 중요하므로 추가로 정리하겠습니다.

아래 예제 결과를 보고, 이해해 보시기 바랍니다. 


    public static void main(String[] args)
    {
        int x = 0xFFFF;
        int y = 0xFFF0;

        System.out.printf("%x\n", (x & y));
        System.out.printf("%x\n", (x | y));
        System.out.printf("%x\n", (x ^ y));
        System.out.printf("%x\n", ~x);
        System.out.printf("%x\n", (x << 4));
        System.out.printf("%x\n", (x >> 4));
        System.out.printf("%x\n", (-1 >>> 4));

        System.out.println("Hello World!");
    }



 
// 결과
fff0
ffff
f
ffff0000
ffff0
fff
fffffff
Hello World!


'프로그래밍 > Java' 카테고리의 다른 글

[Java] 제어문 두번째, switch case break 문  (0) 2016.05.09
[Java] 제어문 첫번째, If 문  (0) 2016.05.02
[Java] 연산자-4  (0) 2016.04.14
[Java] 연산자-3  (0) 2016.04.10
[Java] 연산자-2  (0) 2016.04.08

+ Recent posts