为什么这个程序不能正常工作?我将一个字节数组转换为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.为什么你要转换成长呢? –