import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Informatik II - FS2009
* Uebungsserie 0, Aufgabe 2
* Template for Char2Bin.java
* * The Char2Bin class provides functionalities to input and * display a text string on the console and to compute its * binary represenation. * * @author Silvia Santini * @author Philipp Bolliger */ public class Char2Bin { public static void main(String[] args) throws IOException { System.out.print("Enter text: "); /*read input*/ BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String text = r.readLine(); /*print output*/ int len = text.length(); System.out.print("You entered " + len + " characters: "); int i = 0; int n = 0; /*Hinweis zur Loesung!*/ char c; while (i < len) { c = text.charAt(i); System.out.print(c + " "); i++; } } /** * Converts an integer n in its binary representation as a bit string * @param n the integer number to convert * @return the binary representation of n as a bit string * */ public static String convert(int n) { String bin = ""; int z; if (n == 0) { return "0"; } while (n > 0) { z = n % 2; bin = z + bin; n = n / 2; } return bin; } }