我有一个用Java编写的类型代码:
public static String asHex(byte[] buf)
{
StringBuilder strbuf = new StringBuilder(buf.length << 1);
for (byte aByte : buf) {
if (((int) aByte & 0xff) < 0x10) {
strbuf.append('0');
}
strbuf.append(Long.toString((int) aByte & 0xff, 16));
}
return strbuf.toString();
}这和PHP中的base64_decode是一样的吗?
发布于 2011-05-24 07:55:28
发布于 2011-05-25 20:12:22
正如@James所说: bin2hex会这样做:
<?php
$str = "Hello world!";
echo bin2hex($str) . "<br />";
?>所产生的结果与
static public void main(String args[]) {
String str= "Hello world!";
byte[] x = str.getBytes();
String s = asHex(x);
System.out.println (s);
}
public static String asHex (byte buf[]) {
StringBuffer strbuf = new StringBuffer(buf.length * 2);
int i;
for (i = 0; i < buf.length; i++) {
if (((int) buf[i] & 0xff) < 0x10)
strbuf.append("0");
strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
}
return strbuf.toString();
}https://stackoverflow.com/questions/6104316
复制相似问题