티스토리 뷰
int num = 92;
//10 -> 2, 8, 16
String binNum = Integer.toBinaryString(num);
String octNum = Integer.toOctalString(num);
String hexNum = Integer.toHexString(num);
System.out.println(binNum); //1011100
System.out.println(octNum); //134
System.out.println(hexNum); //5c
//2, 8, 16 -> 10
int binToDec = Integer.parseInt(binNum, 2);
int octToDec = Integer.parseInt(octNum, 8);
int hexToDec = Integer.parseInt(hexNum, 16);
System.out.println(binToDec); //92
System.out.println(octToDec); //92
System.out.println(hexToDec); //92
참고
자바 10진수 <-> 2진수, 8진수, 16진수 변환
자바 2진수, 8진수, 16진수 변환 시에는 Integer 클래스 API를 활용하면 편하다. (참고 : https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html) 10진수 -> 2진수, 8진수, 16진수 변환 1 2 3 4 5 6..
donggov.tistory.com
'Language > Java' 카테고리의 다른 글
JVM의 Garbage Collector (0) | 2021.04.09 |
---|---|
Java Virtual Machine 구조 (0) | 2021.04.09 |
데이터 타입별 형변환 방법 (0) | 2021.02.22 |
copyOf() / copyOfRange() (0) | 2021.02.18 |
for-each / Iterator (0) | 2021.02.18 |
댓글