测试代码:
cs
unsafe public void ceshi()
{
byte[] by = BitConverter.GetBytes(0x12345678);
Debug.WriteLine(" byte[0] = 0x" + by[0].ToString("x2"));
Debug.WriteLine(" byte[1] = 0x" + by[1].ToString("x2"));
Debug.WriteLine(" byte[2] = 0x" + by[2].ToString("x2"));
Debug.WriteLine(" byte[3] = 0x" + by[3].ToString("x2"));
for( int i = 0; i < 4;i ++)
{
fixed (byte* pB = &by[i])
{
ulong addr = (ulong)pB; // 得到内存的地址
Debug.WriteLine($" byte[{i}]地址 = 0x" + addr.ToString("x2"));
}
}
}
输出结果
byte0 = 0x78
byte1 = 0x56
byte2 = 0x34
byte3 = 0x12
byte0地址 = 0x29a7af0
byte1地址 = 0x29a7af1
byte2地址 = 0x29a7af2
byte3地址 = 0x29a7af3
结论:
0 = 低字节
3 = 高字节
参考链接
单片机大小端模式-CSDN博客
https://blog.csdn.net/anlog/article/details/135338624
特此记录
anlog
2024年1月5日