爲什麼這個程序不能正常工作?我將一個字節數組轉換爲long。然後從長我轉換回一個字節數組。生成的字節數組與原始數據不一樣。C#字節[]長反轉不起作用
class Program
{
static void Main(string[] args)
{
byte[] myBytes = { 0, 0, 0, 32, 56, 99, 87, 34, 56, 56, 34, 33, 67
, 56, 66, 72, 1, 0, 0, 56, 0, 22};
long data = BitConverter.ToInt64(myBytes, 0);
byte[] byteData = BitConverter.GetBytes(data);
Console.WriteLine("byte array: " + BitConverter.ToString(myBytes));
Console.WriteLine("byte array: " + BitConverter.ToString(byteData));
}
}
由於方法名稱('ToInt64')意味着long是64位(8字節)長。 – I4V
它不*工作*但* *不按預期工作*。 –
是的,你在那個數組中有22個字節,int64是8.爲什麼你要轉換成長呢? –