/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
/* */ public static String toHexString
(byte[] bytes
) { /* 215 */ StringBuilder hexString = new StringBuilder();
/* 216 */ for (int i = 0; i < bytes.length; ++i) {
/* 217 */ hexString.
append(Integer.
toHexString(0xFF
& bytes
[i
])); /* */ }
/* 219 */ return hexString.toString();
/* */ }
private static String toHex
(byte[] checksumArray
) {
StringBuilder result = new StringBuilder();
for (byte checksumByte : checksumArray)
{
String hex
= Integer.
toString((checksumByte
& 0xff
) + 0x100,
16).
substring(1); result.append(hex);
}
return result.toString();
}
private static final char[] hexchars = "0123456789abcdef".toCharArray();
private static String toHexRL
(byte[] checksumArray
) { int len = checksumArray.length * 2;
char[] hchars = new char[len];
int pos = 0;
for (byte b : checksumArray) {
hchars[pos++] = hexchars[(b>>4) & 0xf];
hchars[pos++] = hexchars[b & 0xf];
}
}
public static void main
(String[] args
) { byte[][] testcases = new byte[][]{
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
};
for (byte[] tc : testcases) {
System.
out.
printf("Input %s\n CXF %s\n OP %s\n RL %s",
Arrays.
toString(tc
), toHexString
(tc
), toHex
(tc
), toHexRL
(tc
)); }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCS8qICAgICAqLyAgIHB1YmxpYyBzdGF0aWMgU3RyaW5nIHRvSGV4U3RyaW5nKGJ5dGVbXSBieXRlcykgewoJCS8qIDIxNSAqL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IDogY2hlY2tzdW1BcnJheSkgewoJCQloY2hhcnNbcG9zKytdID0gaGV4Y2hhcnNbKGI+PjQpICYgMHhmXTsKCQkJaGNoYXJzW3BvcysrXSA9IGhleGNoYXJzW2IgJiAweGZdOwoJCX0KCSAgICByZXR1cm4gbmV3IFN0cmluZyhoY2hhcnMpOwoJfQoJCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CgkJYnl0ZVtdW10gdGVzdGNhc2VzID0gbmV3IGJ5dGVbXVtdewoJCQl7MSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOSwgMTAsIDExLCAxMiwgMTMsIDE0LCAxNSwgMTYsIDE3LCAxOCwgMTksIDIwfQoJCX07CgkJZm9yIChieXRlW10gdGMgOiB0ZXN0Y2FzZXMpIHsKCQkJU3lzdGVtLm91dC5wcmludGYoIklucHV0ICVzXG4gIENYRiAlc1xuICBPUCAgJXNcbiAgUkwgICVzIiwgQXJyYXlzLnRvU3RyaW5nKHRjKSwgdG9IZXhTdHJpbmcodGMpLCB0b0hleCh0YyksIHRvSGV4UkwodGMpKTsKCQl9Cgl9Cn0=
Input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
CXF 123456789abcdef1011121314
OP 0102030405060708090a0b0c0d0e0f1011121314
RL 0102030405060708090a0b0c0d0e0f1011121314