import
java.util.HashMap;
public
class
BinaryToHexadecimal {
public
static
void
main(String[] args) {
String binaryNum =
"10101101"
;
HashMap<String, String> hexDict =
new
HashMap<>();
hexDict.put(
"0000"
,
"0"
);
hexDict.put(
"0001"
,
"1"
);
hexDict.put(
"0010"
,
"2"
);
hexDict.put(
"0011"
,
"3"
);
hexDict.put(
"0100"
,
"4"
);
hexDict.put(
"0101"
,
"5"
);
hexDict.put(
"0110"
,
"6"
);
hexDict.put(
"0111"
,
"7"
);
hexDict.put(
"1000"
,
"8"
);
hexDict.put(
"1001"
,
"9"
);
hexDict.put(
"1010"
,
"A"
);
hexDict.put(
"1011"
,
"B"
);
hexDict.put(
"1100"
,
"C"
);
hexDict.put(
"1101"
,
"D"
);
hexDict.put(
"1110"
,
"E"
);
hexDict.put(
"1111"
,
"F"
);
StringBuilder hexNum =
new
StringBuilder();
int
n = binaryNum.length();
if
(n %
4
!=
0
) {
binaryNum =
"0"
.repeat(
4
- n %
4
) + binaryNum;
n = binaryNum.length();
}
for
(
int
i =
0
; i < n; i +=
4
) {
String hexChunk = binaryNum.substring(i, i +
4
);
hexNum.append(hexDict.get(hexChunk));
}
System.out.println(hexNum.toString());
}
}