Aplikasi Konversi String ke Biner

Kode ini saya dapat dari Mas Erik..

<br />
/*
 *author setiyawanjullev
 */

import java.io.*;
public class StringToBiner {

public String doBiner(int bytes)
{

String result ="";

while(bytes >= 1)
{
int hasil = bytes / 2;
int sisa = bytes % 2;
result = sisa+result;
bytes = hasil;
}
return result;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
StringToBiner stb = new StringToBiner();
String kata = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("masukkan kata anda :");
kata = br.readLine();

char [] toChars = kata.toCharArray();

for(int a=0;a<toChars.length;a++)
{
int code = toChars[a];
System.out.println(String.valueOf(toChars[a])+"["+(byte)toChars[a]+"] = "+ stb.doBiner(code));

}
System.out.println("Kata anda adalah : "+kata);
}
}

2 thoughts on “Aplikasi Konversi String ke Biner

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