.: Java :. Konversi Bilangan Biner

package Konversi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Nurul C.
*/
public class binerTodesimal {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader biner= new BufferedReader ( new InputStreamReader ( System.in )) ;
System.out.print ( “Masukan Bilangan Binernya = ” ) ;
String str = biner.readLine () ;
long num = Long.parseLong ( str ) ;
long rem;
while ( num > 0 ){
rem = num % 10 ;
num = num / 10 ;
if ( rem != 0 && rem != 1 ){
System.out.println ( “Ini bukan bilangan biner.” ) ;
System.out.println ( “Silahkan Coba lagi” ) ;
System.exit ( 0 ) ;
}
}
int i= Integer.parseInt ( str, 2 ) ;
System.out.println ( “Desimalnya : ” + i ) ;
}
}

Berikut hasil outputnya :

array

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s