비트 연산자-OperatorEx16

CODEDRAGON Development/Java

반응형

비트연산자

   

소스코드

  1. public class OperatorEx16 {
  2.         public static void main(String[] args)
  3.         {
  4.                 int num1=5;             /* 00000000 00000000 00000000 00000101 */
  5.                 int num2=3;             /* 00000000 00000000 00000000 00000011 */
  6.                 int num3=-1;    /* 11111111 11111111 11111111 11111111 */
  7.                  
  8.                 System.out.println(num1 & num2);
  9.                 // 00000000 00000000 00000000 00000101
  10.                 // 00000000 00000000 00000000 00000011
  11.                 // 00000000 00000000 00000000 00000001
  12.                  
  13.                 System.out.println(num1 | num2);
  14.                 // 00000000 00000000 00000000 00000101
  15.                 // 00000000 00000000 00000000 00000011
  16.                 // 00000000 00000000 00000000 00000111
  17.                  
  18.                 System.out.println(num1 ^ num2);
  19.                 // 00000000 00000000 00000000 00000101
  20.                 // 00000000 00000000 00000000 00000011
  21.                 // 00000000 00000000 00000000 00000110
  22.                  
  23.                 System.out.println(~num3);     
  24.                 // 11111111 11111111 11111111 11111111
  25.                 // 00000000 00000000 00000000 00000000
  26.         }
  27. }


 

   

출력결과

   

   

반응형