카테고리 없음

[JAVA] 10진수 <-> 2진수, 8진수, 16진수

Accept 2024. 1. 27. 20:20

10진수 -> 2진수, 8진수, 16진수

int decimal = 10;

String binary = Integer.toBinaryString(decimal); // 10진수 -> 2진수
String octal = Integer.toOctalString(decimal); // 10진수 -> 8진수
String hexaDecimal = Integer.toHexString(decimal); // 10진수 -> 16진수

2진수, 8진수, 16진수 -> 10진수

int binaryToDecimal = Integer.parseInt(“1010”, 2);
int octalToDecimal = Integer.parseInt(“12”, 8);
int hexaToDecimal = Integer.parseInt(“A”, 16);