我希望在 C# 中编写 Oracle 函数 rawtohex。我正在查看已编写的现有代码,并希望确认它是否准确。
public static string AsHexString1(this char[] chars)
{
StringBuilder sb = new StringBuilder();
foreach (var ch in chars)
{
int lowNibble = (int)ch % 16;
int highNibble = (int)ch / 16;
sb.Append(highNibble <= 9 ? highNibble.ToString() : ((char)('A' + (highNibble - 10))).ToString());
sb.Append(lowNibble <= 9 ? lowNibble.ToString() : ((char)('A' + (lowNibble - 10))).ToString());
}
return sb.ToString();
}
谢谢。