来信大神,帮忙帮下面的JAVA代码转成c#代码
private static final String HEX_CHARS = "0123456789abcdef";
public static String toHexString(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
sb.append(HexUtil.HEX_CHARS.charAt(b[i] >>> 4 & 0x0F));
sb.append(HexUtil.HEX_CHARS.charAt(b[i] & 0x0F));
}
return sb.toString();
}
private const String HEX_CHARS = "0123456789abcdef"; public static String toHexString(byte[] b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.Length; i++) { sb.Append(HEX_CHARS.ElementAt(b[i] = 4 & 0x0F)); sb.Append(HEX_CHARS.ElementAt(b[i] = 0x0F)); } return sb.ToString(); }
最好是找一下 HexUtil 这个C#下的引用
http://www.thinksaas.cn/group/topic/397013/
private const string HEX_CHARS = "0123456789abcdef"; public static string toHexString(byte[] b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.Length; i++) { sb.Append(HEX_CHARS.Substring((b[i] / (int)(Math.Pow(2, 4))) & 0x0F, 1)); sb.Append(HEX_CHARS.Substring(b[i] & 0x0F, 1)); } return sb.ToString(); }
试试看