/* Aufgabe 7 Prakash Punnoor */

class Aufgabe7
{
	public static void main ( String[] args )
	{
		if (args.length == 0) {
			System.out.println("Bitte Hexzahl (ohne Spaces) als Parameter angeben");
			return;
		}

		System.out.println(hex2bin(args[0]));

		 /* System.out.println(hex2bin_pfusch(args[0]));*/
		return;
	}

	/* Dies wäre am einfachsten, aber laut Aufgabenstellung nicht erlaubt */
	public static String hex2bin_pfusch(String hex)
	{
		return Integer.toBinaryString(
			Integer.parseInt(hex, 16));
	}

	public static String hex2bin(String hex)
	{
		/* Hex läßt sich einfach mittels Tabelle abbilden */
		String bin_map[] = {
			"0000", "0001", "0010", "0011",
			"0100", "0101", "0110", "0111",
			"1000", "1001", "1010", "1011",
			"1100", "1101", "1110", "1111"
		};

		/* Wir wollen keine führende Null */
		String bin_map_first[] = {
			    "",    "1",   "10",   "11",
			 "100",  "101",  "110",  "111",
			"1000", "1001", "1010", "1011",
			"1100", "1101", "1110", "1111"
		};

		/* relativ selbsterklärend; wir gehen alle Hexziffern durch
		und picken das richtige Element aus der Tabelle und hängen
		es der Ausgabe an */
		String result = "";
		int i;
		
		int length = hex.length();

		/* Führende Nullen der Eingabe entfernen */
		for (i = 0; i < length; ++i)
			if (hex.charAt(i) != '0') break;
			
		/* Es wurden nur Nullen eingegeben */
		if (i == length)
			return "0";

		char c = hex.charAt(i);
		++i;

		/* erste Ziffer ohne führende Null */
		if (c >= '0'  &&  c <= '9')
			result += bin_map_first[c - '0'];
		else if (c >= 'A'  &&  c <= 'F')
			result += bin_map_first[c - 'A' + 10];
		else if (c >= 'a'  &&  c <= 'f')
			result += bin_map_first[c - 'a' + 10];
		else return "invalid input";

		/* restliche Ziffern */
		for (; i < length; ++i) {
			c = hex.charAt(i);

			if (c >= '0'  &&  c <= '9')
				result += bin_map[c - '0'];
			else if (c >= 'A'  &&  c <= 'F')
				result += bin_map[c - 'A' + 10];
			else if (c >= 'a'  &&  c <= 'f')
				result += bin_map[c - 'a' + 10];
			else return "invalid input";
		}
		
		return result;
	}
}
