如果我有一個字節數組表示從文件讀取的數字,字節數組如何轉換爲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