【发布时间】:2011-09-04 03:26:20
【问题描述】:
我正在尝试在 C# 中进行一些转换,但我不知道该怎么做:
private int byteArray2Int(byte[] bytes)
{
// bytes = new byte[] {0x01, 0x03, 0x04};
// how to convert this byte array to an int?
return BitConverter.ToInt32(bytes, 0); // is this correct?
// because if I have a bytes = new byte [] {0x32} => I got an exception
}
private string byteArray2String(byte[] bytes)
{
return System.Text.ASCIIEncoding.ASCII.GetString(bytes);
// but then I got a problem that if a byte is 0x00, it show 0x20
}
谁能给我一些想法?
【问题讨论】:
-
如果你喜欢边缘生活,你可以使用演员表。
标签: c#