コード例 #1
0
 @Override
 public String format(final int[] array)
     throws NullPointerException, IllegalArgumentException {
   final int length = array.length + 1;
   final char[] result = new char[length];
   for (int i = 0; i < length; ) {
     final int value = array[i >> 1];
     result[i++] = FEMBinary.toChar((value >> 4) & 0xF);
     result[i++] = FEMBinary.toChar((value >> 0) & 0xF);
   }
   return new String(result);
 }
コード例 #2
0
 @Override
 public int[] parse(final String string)
     throws NullPointerException, IllegalArgumentException {
   final char[] source = string.toCharArray();
   final int length = source.length;
   if ((length & 1) != 0) throw new IllegalArgumentException();
   final int[] result = new int[length >> 1];
   for (int i = 0; i < length; ) {
     final int x = i >> 1;
     final int hi = FEMBinary.toDigit(source[i++]);
     final int lo = FEMBinary.toDigit(source[i++]);
     result[x] = (byte) ((hi << 4) | (lo << 0));
   }
   return result;
 }