Sabtu, Oktober 01, 2011

KONVERSI BINER to DECIMAL (MIDLET)

PSVM->{
String inputan = "100110";
int array[] = new int[inputan.length()];
int jodoh[] = new int[10];
int as[] = new int[10];

jodoh[0] = 1;
jodoh[1] = 2;
jodoh[2] = 4;
jodoh[3] = 8;
jodoh[4] = 16;
jodoh[5] = 32;
jodoh[6] = 64;
jodoh[7] = 128;
jodoh[8] = 256;
jodoh[9] = 512;

int simpen = 0;

for (int i = inputan.length() - 1; i >= 0; i--) {
array[i] = Integer.parseInt(String.valueOf(inputan.charAt(i)));
int a = 0, c = 0;
int temp = array[i] * jodoh[as[a]++];
simpen += temp;
if (i == 0) {
System.out.print("hasil : " + simpen);
}
}
System.out.println("");

Source : Utak-atik dhewe... ;)
}

Tidak ada komentar:

Posting Komentar