code: public static byte[] toByteArray(CharSequence hexString, int offset, int length) {
          if (hexString == null) {
              return null;
          }
          assertOffsetLengthValid(offset, length, hexString.length());
  
          // a hex string must be in increments of 2
          if ((length % 2) != 0) {
              throw new IllegalArgumentException("The hex string did not contain an even number of characters [actual=" + length + "]");
          }
          
          // convert hex string to byte array
          byte[] bytes = new byte[length/2];
  
          int j = 0;
          int end = offset+length;
  
          for (int i = offset; i < end; i += 2) {
              int highNibble = hexCharToIntValue(hexString.charAt(i));
              int lowNibble = hexCharToIntValue(hexString.charAt(i+1));
              bytes[j++] = (byte)(((highNibble << 4) & 0xF0) | (lowNibble & 0x0F));
          }
          return bytes;
      }
docs: Creates a byte array from a CharSequence (String, StringBuilder, etc.)
  containing only valid hexidecimal formatted characters.
  Each grouping of 2 characters represent a byte in "Big Endian" format.
  The hex CharSequence must be an even length of characters. For example, a String
  of "1234" would return the byte array { 0x12, 0x34 }.
  @param hexString The String, StringBuilder, etc. that contains the
  sequence of hexidecimal character values.
  @param offset The offset within the sequence to start from.  If the offset
  is invalid, will cause an IllegalArgumentException.
  @param length The length from the offset to convert. If the length
  is invalid, will cause an IllegalArgumentException.
  @return A new byte array representing the sequence of bytes created from
  the sequence of hexidecimal characters.  If the hexString is null,
  then this method will return null.