#C633. Binary to Hexadecimal Conversion
Binary to Hexadecimal Conversion
Binary to Hexadecimal Conversion
You are given a binary string, and your task is to convert it to its corresponding hexadecimal representation. The conversion should work by first padding the binary string with leading zeros so that its length is a multiple of 4. Then divide the padded binary string into groups of 4 bits and convert each group to its hexadecimal digit using the mapping below:
$$\begin{array}{|c|c|}\hline 0000 & 0\\ \hline 0001 & 1\\ \hline 0010 & 2\\ \hline 0011 & 3\\ \hline 0100 & 4\\ \hline 0101 & 5\\ \hline 0110 & 6\\ \hline 0111 & 7\\ \hline 1000 & 8\\ \hline 1001 & 9\\ \hline 1010 & A\\ \hline 1011 & B\\ \hline 1100 & C\\ \hline 1101 & D\\ \hline 1110 & E\\ \hline 1111 & F\\ \hline \end{array}$$
For example, the binary string "1101" should be padded to "1101" (already a multiple of 4) and then converted to "D". Similarly, "111111" is padded to "00111111" and converted to "3F".
Your program should read the input from standard input (stdin) and output the hexadecimal string to standard output (stdout).
inputFormat
The input consists of a single line containing a binary string. The binary string is guaranteed to be non-empty and may contain leading zeros.
Example:
1101
outputFormat
Output the hexadecimal representation corresponding to the input binary string. The output should be in uppercase letters.
Example:
D## sample
1101
D