fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) throws IOException {
  11. System.in));
  12. HashMap<Character, String> map = new HashMap<Character, String>();
  13. map.put('0', "0000");
  14. map.put('1', "0001");
  15. map.put('2', "0010");
  16. map.put('3', "0011");
  17. map.put('4', "0100");
  18. map.put('5', "0101");
  19. map.put('6', "0110");
  20. map.put('7', "0111");
  21. map.put('8', "1000");
  22. map.put('9', "1001");
  23. map.put('A', "1010");
  24. map.put('B', "1011");
  25. map.put('C', "1100");
  26. map.put('D', "1101");
  27. map.put('F', "1111");
  28. System.out.print("Input your Hex Number here : ");
  29. String userInput = input.readLine();
  30. StringBuilder result = new StringBuilder();
  31.  
  32. for (int i = 0; i < userInput.length(); i++) {
  33. /* used for separating the value */
  34. char hexVal = userInput.charAt(i);
  35. String binary = map.get(hexVal);
  36. result.append(binary);
  37. }
  38.  
  39. //Main output
  40. System.out.println("THE BINARY OF " + userInput + ":" + result.toString());
  41.  
  42.  
  43. }
  44. }
Success #stdin #stdout 0.07s 380160KB
stdin
5F
stdout
Input your Hex Number here : THE BINARY OF 5F:01011111