English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

십진수에서 십육진수로 변환하는 Java 프로그램

10진수를 16진수로 변환하는 방법은 두 가지가 있습니다.

메서드1-사용toString()메서드를 사용하면, 16진수 기본수가16따라서 기본수를1610진수를 16진수로 쉽게 변환할 수 있습니다.

예제

public class Demo {
   public static void main(String args[]) {
      int dec = 30;
      //16진수로 변환
      String hex = Integer.toString(dec, 16);
      System.out.println(hex);
   }
}

출력 결과

1e

메서드2-사용toHexString()10진수를 16진수로 변환하는 메서드를 정의합니다;

예제

public class Demo {
   public static void main(String args[]) {
      int dec = 30;
      //16진수로 변환
      String hex = Integer.toHexString(dec);
      System.out.println(hex);
   }
}

출력 결과

1e