JAVA/JAVA Algorithm, Datastruct

[Algorithm] JAVA 코드업 기초 100제 (기초-비트단위논리연산) 1059 ~ 1062

큐범 2022. 9. 2. 03:10

비트단위(bitwise)연산자

~(bitwise not)

&(bitwise and)

|(bitwise or)

^(bitwise xor)

<<(bitwise left shift)

>>(bitwise right shift)

 

1059 : [기초-비트단위논리연산] 비트단위로 NOT 하여 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		
		System.out.printf("%d",~s);
	}

1060 : [기초-비트단위논리연산] 비트단위로 AND 하여 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] data = s.split(" ");
		
		System.out.println(Integer.valueOf(data[0])&Integer.valueOf(data[1]));
	}

1061 : [기초-비트단위논리연산] 비트단위로 OR 하여 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] data = s.split(" ");
		
		System.out.println(Integer.valueOf(data[0]) | Integer.valueOf(data[1]));
	}

1062 : [기초-비트단위논리연산] 비트단위로 XOR 하여 출력하기(설명)

public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] data = s.split(" ");
		
		System.out.println(Integer.valueOf(data[0]) ^ Integer.valueOf(data[1]));
	}