진수 변환하기( 10진수, 2/8/16진수 )

Study/Java 2021. 3. 4. 11:02 Posted by meanoflife
반응형

진수 변환하기

 

"알면 상식이지만, 모르면 미지의 세계다"

 

아는 지인의 카톡에 적혀 있던 문구인데, 공감을 많이 했던 내용입니다. 알면 아무것도 아닌데, 모를 때는 정말... ㄷㄷㄷ 한것들이 많은 것 같습니다.

 

public static void main(String[] args) {

    // 10진수를 변환

    System.out.println( "10진수 ->  2진수 : " +

Integer.toBinaryString( 17 ) );

    System.out.println( "10진수 ->  8진수 : " + Integer.toOctaString( 17 ) );

    System.out.println( "10진수 -> 16진수 : " + Integer.toHexString( 17 ) );

 

    System.out.println( " 2진수 -> 10진수 : " + Integer.parseInt( "10001", 2 ) );

    System.out.println( " 8진수 -> 10진수 : " + Integer.parseInt( "21", 8 ) );

    System.out.println( "16진수 -> 10진수 : " + Integer.parseInt( "11", 16 ) );

}

 

소스를 보니, 너무 단순합니다.

역시 알면.....

 

The End.

반응형