我正在尝试将像"testing123“这样的字符串转换成java中的十六进制形式。我目前使用的是BlueJ。
要将它转换回来,除了向后转换之外,它是不是一样的东西?
发布于 2010-01-28 04:12:42
这里有一个将其转换为十六进制的简单方法:
public String toHex(String arg) {
return String.format("%040x", new BigInteger(1, arg.getBytes(/*YOUR_CHARSET?*/)));
}
发布于 2010-10-15 17:06:39
为了确保十六进制的长度始终为40个字符,BigInteger必须为正:
public String toHex(String arg) {
return String.format("%x", new BigInteger(1, arg.getBytes(/*YOUR_CHARSET?*/)));
}
发布于 2012-01-25 03:57:09
import org.apache.commons.codec.binary.Hex;
...
String hexString = Hex.encodeHexString(myString.getBytes(/* charset */));
http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Hex.html
https://stackoverflow.com/questions/923863
复制相似问题