fork download
  1. import java.util.Arrays;
  2.  
  3. public final class Main {
  4.  
  5. static byte[] decode(final String enc) {
  6. final long val = Long.parseLong(enc, 16);
  7. final byte[] raw = new byte[] {
  8. (byte) ((val & 0xff00000000000000L) >> 56),
  9. (byte) ((val & 0xff000000000000L) >> 48),
  10. (byte) ((val & 0xff0000000000L) >> 40),
  11. (byte) ((val & 0xff00000000L) >> 32),
  12. (byte) ((val & 0xff000000) >> 24),
  13. (byte) ((val & 0xff0000) >> 16),
  14. (byte) ((val & 0xff00) >> 8),
  15. (byte) (val & 0xffL)
  16. };
  17. final int n = enc.length() >> 1;
  18. final byte[] trimmed = new byte[n];
  19. System.arraycopy(raw, 8 - n, trimmed, 0, n);
  20. return trimmed;
  21. }
  22.  
  23. public static void main(final String[] argv) {
  24. System.out.println(Arrays.equals(
  25. new byte[] { (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94, (byte) 0x95 },
  26. decode("9192939495")
  27. ));
  28. }
  29. }
Success #stdin #stdout 0.06s 215552KB
stdin
Standard input is empty
stdout
true