- 2진수 -> 10진수
Integer.valueOf(문자열, 2)
- 10진수 -> 2진수
Integer.toBinaryString(10진수)
public class Ex10 {
public static void main(String[] args) {
String bin = "101";
int dec = 5;
System.out.println("101을 10진수로 변환하면 : " + Integer.valueOf(bin, 2));
System.out.println("5를 2진수로 변환하면 : " + Integer.toBinaryString(dec));
}
}
- 2진수끼리 더한 값 구하기(2진수로 출력)
public class Ex10 {
public static void main(String[] args) {
String bin1 = "101";
String bin2 = "111";
System.out.println( "101 + 111 : " + Integer.toBinaryString((Integer.valueOf(bin1, 2) + Integer.valueOf(bin2, 2))) );
}
}
'자바(JAVA)' 카테고리의 다른 글
☆이클립스 개인 설정 (0) | 2023.01.14 |
---|---|
[자바(Java)] BigInteger , BigDecimal (0) | 2023.01.06 |
[자바(Java)] char <-> int 변환 (0) | 2022.12.31 |
[자바(Java)] 스트림 활용 (0) | 2022.12.31 |
[자바(Java)] 문자열 <-> 배열 변환 (0) | 2022.12.31 |