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

Java 프로그램이 이진수를 십진수로 변환하다

parseInt()두 번째 매개변수는 기본 값을 가지므로 두 번째 매개변수를 사용하여2메서드는 다음과 같은 방법을 가집니다. 이parseInt()메서드는 다음과 같은 두 가지 형식을 가집니다.

static int parseInt(String s)
static int parseInt(String s, int radix)

이진을 십진수로 변환하려면 사용2nd 문법을 사용하여 기본수를 추가2،이진 기본数为2。

Integer.parseInt("1110", 2)

예제

public class Demo {
   public static void main( String args[] ) {
      //소수점으로 변환
      System.out.println(Integer.parseInt("1110", 2));
   }
}

출력 결과

14
좋아할 만한 것