import java.io.*; public class TexttoBinary { 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("Type the number to parse: "); int number = Integer.parseInt(in.readLine()); int Bit; String result = ""; for (int i = maxBytes*8; i >= 0; i--) { Bit = 1 << i; if (number >= Bit) { result += 1; number -= Bit; } else { result += 0; } } System.out.println(result); } catch (NumberFormatException e) { System.exit(0); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } while (true); } }