.: Java :. Konversi Bilangan Biner ke Desimal

package Konversi;

import javax.swing.JOptionPane;

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

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int a;
int n=0;
int x=0;
float hsl=0;
String biner ;

biner = JOptionPane.showInputDialog(“Ketikkan Bilangan Biner :”);
a = Integer.parseInt(biner);

JOptionPane.showMessageDialog(null, “Bilangan Biner = “+biner);
System.out.println(“Bilangan binernya >> “+biner);
System.out.println(“Konversi ke Desimalnya adalah :”);
System.out.println(“********************************”);
System.out.println();
hasil(a,n,x,hsl);
System.out.println(“——————————–“);
}
static void hasil (int a, int n, int x, float hsl)
{

float c, d=2, e=0;
int b;
if(a>=10)
{
b=a%10;
}else{
b=a;
}
if(a>0)
{
c = (float) (b * Math.pow(d, n));
hsl = hsl + c;
if(b!=a)
System.out.println(c+ ” + “);
else
System.out.println(c+ ” = ” + hsl);
JOptionPane.showMessageDialog(null,c+ ” = ” + hsl);
n++;
hasil(a/10,n,x,hsl);
}
}
}

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