[C#/General] 바이트배열을 int로 변환하는 방법


[C#/General] 바이트배열을 int로 변환하는 방법

> little-endian인 경우 (중요한 바이트가 먼저 저장되어 있다면) 배열을 역방향으로 설정후 ToInt32 호출하여 변환. byte[] bytes = { 0, 0, 0, 25 }; // little-endian 일 경우, 역배열시킨다. // reverse the byte array. if (BitConverter.IsLittleEndian) Array.Reverse(bytes); // ToInt32를 이용하여 int형으로 변환. int i = BitConverter.ToInt32(bytes, 0); Console.WriteLine("int: {0}", i); // 출력 : int: 25


원문링크 : [C#/General] 바이트배열을 int로 변환하는 방법