/* BinaryConvRevised
 * 
 * A program to convert a decimal number less than 256 to its
 * 8-bit binary representation
 *
 * Nadeem Abdul Hamid
 * CSC 120 A - Fall 2004
 */

import java.io.*;

public class BinaryConvRevised {

    static int num;
    
    public static String processPV(int pv, String str) {
    	if (num >= pv) { str += "1"; num -= pv; }
	    else str += "0";
        return str;
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter a number from 0 to 255 to convert to binary: ");
        num = Integer.parseInt(in.readLine());
        if (num < 0 || num >= 256) {
            System.out.println("You typed an invalid input.");
        } else {
            String bin = "";
            bin = processPV(128,bin);
            bin = processPV(64,bin);
            bin = processPV(32,bin);
            bin = processPV(16,bin);
            bin = processPV(8,bin);
            bin = processPV(4,bin);
            bin = processPV(2,bin);
            bin = processPV(1,bin);
        
            System.out.println("The number in binary is: " + bin);
        } 
    }

}