Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- C#프로그래밍
- Algorithm
- 사용자입력
- 백준
- 백준파이썬
- VARIABLE
- 코드업
- 코딩테스트
- 제어구조
- 프로그래머스파이썬
- 알고리즘
- 자바
- SWEA
- SWEA파이썬
- Literal
- 코드업100제
- 디자인패턴
- 코드업100제자바
- 개발입문
- 코드업자바
- c#
- Codeup
- Java
- 리터럴
- 자바연산자
- C#변수
- 변수
- 기초프로그래밍
- 자바클래스
- 수학연산
Archives
- Today
- Total
제니노트
[기초-비트단위논리연산] 1059-1062 [자바] 본문
반응형
1059
import java.io.*;
public class Main{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
int a = Integer.parseInt(str);
System.out.print(~a);
}
}
1060
입력된 정수 두 개를 비트단위로 and 연산한 후 그 결과를 정수로 출력해보자.
비트단위(bitwise)연산자 &를 사용하면 된다.(and, ampersand, 앰퍼센드라고 읽는다.)
import java.io.*;
import java.util.StringTokenizer;
public class Main{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str," ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.print(a&b);
}
}
1061
입력된 정수 두 개를 비트단위로 or 연산한 후 그 결과를 정수로 출력해보자.
비트단위(bitwise) 연산자 |(or, vertical bar, 버티컬바)를 사용하면 된다.
import java.io.*;
import java.util.StringTokenizer;
public class Main{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str," ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.print(a|b);
}
}
1062
입력된 정수 두 개를 비트단위로 xor 연산한 후 그 결과를 정수로 출력해보자.
비트단위(bitwise) 연산자 ^(xor, circumflex/caret, 서컴플렉스/카릿)를 사용하면 된다.
import java.io.*;
import java.util.StringTokenizer;
public class Main{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str," ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.print(a^b);
}
}
반응형
'코딩테스트 > 코드업' 카테고리의 다른 글
[기초-조건/선택실행구조] 1065-1070 [자바] (0) | 2023.01.31 |
---|---|
[기초-삼항연산] 1063-1064 [자바] (0) | 2023.01.31 |
[기초 - 논리연산] 1053 - 1058 [자바] (0) | 2023.01.17 |
[기초-비교연산] 1049-1052 [자바] (0) | 2023.01.17 |
[기초 - 비트시프트연산] 1047-1048 [자바] (0) | 2023.01.17 |
Comments