code: public static String binaryToHex(byte[] data, int offset, int length)
      {
          assert offset < data.length && offset >= 0 : offset + ", " + data.length;
          int end = offset + length;
          assert end <= data.length && end >= 0 : offset + ", " + length + ", " + data.length;
  
          char[] chars = new char[length*2];
          int j = 0;
          for (int i = offset; i < end; i++) {
              int b = data[i];
              chars[j++] = hexDigit(b >>> 4 & 0xF);
              chars[j++] = hexDigit(b & 0xF);
          }
  
          return new String(chars);
      }
docs: Convert a string of binary bytes to the equivalent hexadecimal string.
  The resulting String will have two characters for every byte in the
  input.