프로그래밍/.Net
BitConvert big endian <-> little endian 변환하기
강태공97
2014. 1. 17. 21:20
일반 OS는 big endian 방식임.
즉, uint a = 0x12345678; 0x12 34 56 78;
little endian으로 변경하면..
uint b = 0x12345678; -> 0x78 56 34 12 가 됨
// Big Endian을 little엔디안으로 return UInt32
static UInt32 _fnBigToLittleEndian_UInt(UInt32 bigNumber)
{
byte[] temp = new byte[4];
temp = BitConverter.GetBytes(bigNumber);
Array.Reverse(temp);
return BitConverter.ToUInt32(temp, 0);
}
// Big Endian을 little엔디안으로 return Byte[]
static Byte[] _fnBigToLittleEndian_Byte(UInt32 bigNumber)
{
byte[] temp = new byte[4];
temp = BitConverter.GetBytes(bigNumber);
return temp;
}