Konversi Biner ke Desimal dengan Java

Tinggal copas aja ke Netbeans…
Try it…

import java.util.Scanner;
public class BinerToDec {
public static void main ( String[] args ){
Scanner input = new Scanner(System.in);
int a;
int m =0;
int x = 0;
double hsl=0;

System.out.print(“Masukkan Bilangan Biner : “);
a = input.nextInt();

System.out.print(“Konversi ke Desimal : “);
System.out.println();
hasil(a,m, x,hsl);
System.out.println();
}
static void hasil(int a, int m, int x,double hsl)
{

double c, d=2, e=0;
int b;
if(a>=10)
{
b = a%10;
} else {
b = a;
}
if(a>0)
{
c = b * Math.pow(d,m);
hsl=hsl+c;
if(b!=a)
System.out.print(c+” + “);
else
System.out.print(c+” = “+hsl);
m++;
hasil(a/10,m, x,hsl);
}
}
}

1 Comment »

  1. machsumlola Said:

    bro itu nilainya di masukan sebelah mana bingug ini


{ RSS feed for comments on this post} · { TrackBack URI }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: