如果我有一个字节数组表示从文件读取的数字,字节数组如何转换为Int16/short?C# - 将字节代表字符数转换为Int16
byte[] bytes = new byte[]{45,49,54,50 } //Byte array representing "-162" from text file
short value = 0; //How to convert to -162 as a short here?
尝试使用BitConverter.ToInt16(字节,0),但该值不正确。
编辑:寻找不使用字符串转换的解决方案。
您需要将它们转换为字符串,然后解析字符串。 – willaien
(短)BitConverter.ToInt32(字节) – adrianm
实际上寻找一个解决方案,使用最少量的内存(试图避免字符串转换) – user2966445