Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String hexNum = reader.readLine();
- StringBuilder builder = new StringBuilder();
- ArrayList<Character> hexValues = new ArrayList<>(Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'));
- for (int i = 0; i < hexNum.length(); i++) {
- char currentChar = hexNum.charAt(i);
- int currentN = hexValues.indexOf(currentChar);
- String currentBinary = "";
- for (int j = 0; j < 4; j++) {
- currentBinary = currentN % 2 + currentBinary;
- currentN /= 2;
- }
- builder.append(currentBinary);
- }
- System.out.println(builder.toString().replaceFirst("^0+(?!$)", ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement