import java.util.Scanner;
class PPROG_pl6_ex8 {
public static final Scanner input
= new Scanner
(System.
in);
private static final int BASE = 16;
private static final String[] HEX_DIGITS
= "0123456789ABCDEF".
split("");
public static void main
(String[] args
) { int num;
do {
num = askNum();
System.
out.
println(num
+ " -> " + convertToHex
(num
)); } while (num != 0);
}
private static int askNum() {
//System.out.println("Introduza o número");
return Integer.
parseInt(input.
nextLine()); }
public static String convertToHex
(int num
) { if (num == 0) return "0";
boolean negativo = num < 0;
if (negativo) num = -num;
do {
int alg = num % BASE;
num /= BASE;
String valueOfAlg
= HEX_DIGITS
[alg
]; resposta = valueOfAlg + resposta;
} while (num != 0);
if (negativo) resposta = "-" + resposta;
return resposta;
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKY2xhc3MgUFBST0dfcGw2X2V4OCB7CgogICAgcHVibGljIHN0YXRpYyBmaW5hbCBTY2FubmVyIGlucHV0ID0gbmV3IFNjYW5uZXIoU3lzdGVtLmluKTsKCiAgICBwcml2YXRlIHN0YXRpYyBmaW5hbCBpbnQgQkFTRSA9IDE2OwogICAgcHJpdmF0ZSBzdGF0aWMgZmluYWwgU3RyaW5nW10gSEVYX0RJR0lUUyA9ICIwMTIzNDU2Nzg5QUJDREVGIi5zcGxpdCgiIik7CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIGludCBudW07CiAgICAgICAgZG8gewogICAgICAgICAgICBudW0gPSBhc2tOdW0oKTsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKG51bSArICIgLT4gIiArIGNvbnZlcnRUb0hleChudW0pKTsKICAgICAgICB9IHdoaWxlIChudW0gIT0gMCk7CiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgaW50IGFza051bSgpIHsKICAgICAgICAvL1N5c3RlbS5vdXQucHJpbnRsbigiSW50cm9kdXphIG8gbsO6bWVybyIpOwogICAgICAgIHJldHVybiBJbnRlZ2VyLnBhcnNlSW50KGlucHV0Lm5leHRMaW5lKCkpOwogICAgfQoKICAgIHB1YmxpYyBzdGF0aWMgU3RyaW5nIGNvbnZlcnRUb0hleChpbnQgbnVtKSB7CiAgICAgICAgaWYgKG51bSA9PSAwKSByZXR1cm4gIjAiOwogICAgICAgIGJvb2xlYW4gbmVnYXRpdm8gPSBudW0gPCAwOwogICAgICAgIGlmIChuZWdhdGl2bykgbnVtID0gLW51bTsKICAgICAgICBTdHJpbmcgcmVzcG9zdGEgPSAiIjsKCiAgICAgICAgZG8gewogICAgICAgICAgICBpbnQgYWxnID0gbnVtICUgQkFTRTsKICAgICAgICAgICAgbnVtIC89IEJBU0U7CiAgICAgICAgICAgIFN0cmluZyB2YWx1ZU9mQWxnID0gSEVYX0RJR0lUU1thbGddOwogICAgICAgICAgICByZXNwb3N0YSA9IHZhbHVlT2ZBbGcgKyByZXNwb3N0YTsKICAgICAgICB9IHdoaWxlIChudW0gIT0gMCk7CgogICAgICAgIGlmIChuZWdhdGl2bykgcmVzcG9zdGEgPSAiLSIgKyByZXNwb3N0YTsKICAgICAgICByZXR1cm4gcmVzcG9zdGE7CiAgICB9Cn0=