C# 16进制byte 数组转字符串
时间: 2023-10-12 22:03:55 浏览: 369
C#16进制与字符串字节数组之间的转换代码
要将C#中的16进制byte数组转换为字符串,可以使用以下代码:
```csharp
private string hexByteToStr(byte[] hexByteAry)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hexByteAry.Length; i++)
{
sb.Append(hexByteAry[i].ToString("X2"));
sb.Append(" ");
}
return sb.ToString().Trim();
}
```
这段代码通过遍历byte数组中的每个元素,将其转换为16进制字符串,并通过StringBuilder来拼接结果。最后返回一个包含所有转换后的16进制字符串的字符串变量。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [【无标题】C# 字符串16进制 16进制字节数组 互转](https://blog.csdn.net/zixiao33/article/details/127898418)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文