앞선 글에서는 JAVA로 산술 연산에 관한 문제와 답안을 작성했다.
[JAVA] 코드업 기초 100문제 - [기초-산술연산] 1031 ~ 1037
오늘 글에서는 코드업 기초 100문제 중 비트시프트연산에 관한 문제와 답안을 정리할 것 이다.
import java.util.Scanner;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a =sc.nextInt();
System.out.printf("%d", a<<1);
}
}
설명) 비트(bit)단위시프트 연산자 : 왼쪽이나, 오른쪽으로 전체 비트를 이동시킬 때, 사용한다.
import java.util.Scanner;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int a =sc.nextInt();
int b =sc.nextInt();
System.out.printf("%d", a<<b);
}
}