Java & Html

[Java] 10진수 <> 2진수, 8진수, 16진수 변환

Maddie.Pyo 2019. 4. 10. 17:48

import java.lang.Integer;

class  EveryDayTest30 {
    public static void main(String[] args) {
        int param = 47;

        // 10 -> 2
        System.out.println("10진수 -> 2진수 : " + Integer.toBinaryString(param));
        // 10 -> 8
        System.out.println("10진수 -> 8진수 : " + Integer.toOctalString(param));
        // 10 -> 16
        System.out.println("10진수 -> 16진수 : " + Integer.toHexString(param));
        // 2 -> 10
        System.out.println("2진수 -> 10진수 :"+ Integer.parseInt(Integer.toBinaryString(param), 2));
        // 8 -> 10
        System.out.println("8진수 -> 10진수 :"+ Integer.parseInt(Integer.toOctalString(param), 8));
        // 16 -> 10
        System.out.println("16진수 -> 10진수 :"+ Integer.parseInt(Integer.toHexString(param), 16));

    }
}