1、byte转String
Encoding.ASCII.GetString(byte\[\]);
2、base64string转byte
byte\[\]=Base64Decoder.Decoder.GetDecoded(string);
3、byte转UInt16
方法一
(UInt16)(bytes0 * 256 + bytes1)
方法二
(UInt16)((bytes0 << 8) | bytes1);
方法三
字节序要对应上,下位机一般高字节在前,C#这个函数是低字节在前
BitConverter.ToInt16(bytes);
4、byte转UInt32
(UInt32)((bytes0 << 24) | (bytes1 << 16) | (bytes2 << 8) | bytes3);
5、byte转Int32
(Int32)((bytes0 << 24) | (bytes1 << 16) | (bytes2 << 8) | bytes3);
6、byte转float
BitConverter.ToSingle(bytes, 0);
7、byte转char
BitConverter.ToSingle(bytes, 0);