特定のバイト配列をintに変換したい。次に、プロセスを逆にしたいと思います。つまり、その int から元のバイト配列を取得したいのです。私はこのようなものがうまくいくと思った:
byte[] myBytes = { 0, 0, 0, 32 };
if (BitConverter.IsLittleEndian)
Array.Reverse(myBytes);
int i = BitConverter.ToInt32(myBytes, 0);
Console.WriteLine("int: {0}", i); // Output: 32
byte[] newBytes = BitConverter.GetBytes(i);
Console.WriteLine("byte array: " + BitConverter.ToString(newBytes));
// Outputs: 20-00-00-00
したがって、元のバイト配列は返されません。私は何を間違っていますか?