daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.         String hexNum = reader.readLine();
  12.         StringBuilder builder = new StringBuilder();
  13.         ArrayList<Character> hexValues = new ArrayList<>(Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'));
  14.         for (int i = 0; i < hexNum.length(); i++) {
  15.             char currentChar = hexNum.charAt(i);
  16.             int currentN = hexValues.indexOf(currentChar);
  17.             String currentBinary = "";
  18.             for (int j = 0; j < 4; j++) {
  19.                 currentBinary = currentN % 2 + currentBinary;
  20.                 currentN /= 2;
  21.             }
  22.             builder.append(currentBinary);
  23.         }
  24.         System.out.println(builder.toString().replaceFirst("^0+(?!$)", ""));
  25.     }
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top