scala 字符串转16进制

  private val hexString: String = "0123456789ABCDEF";
  def encodeHex(str: String): String =
    {
      val bytes = str.getBytes();
      val sb = new StringBuilder(bytes.length * 2);
      for (i <- 0 to bytes.length-1) {
        sb.append(hexString.charAt((bytes(i) & 0xf0) >> 4));
        sb.append(hexString.charAt(bytes(i) & 0x0f) );
      }
      return sb.toString();
    }

你可能感兴趣的:(scala,16进制)