/*
* Program Konversi Text Ke Biner
*/
package programlatih100java;
import java.io.*;
/**
* @author Yuniar_Supardi
*/
public class Main {
private static final int maxBytes = 3;
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
do {
try {
System.out.print("Masukkan Angka Yang Akan Di Proses ? ");
int VarInt = Integer.parseInt(in.readLine());
int bit;
String VarHslStr = "";
for (int i = maxBytes*8; i >= 0; i--) {
bit = 1 << i;
if (VarInt >= bit) {
VarHslStr += 1;
VarInt -= bit;
}
else {
VarHslStr += 0;
}
}
System.out.println(VarHslStr);
}
catch (NumberFormatException e) {
System.exit(0);
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
while (true);
}
}
Komentar
Posting Komentar