测试代码:
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"));
}
}
}
输出结果
byte[0] = 0x78
byte[1] = 0x56
byte[2] = 0x34
byte[3] = 0x12
byte[0]地址 = 0x29a7af0
byte[1]地址 = 0x29a7af1
byte[2]地址 = 0x29a7af2
byte[3]地址 = 0x29a7af3
结论:
0 = 低字节
3 = 高字节
参考链接
单片机大小端模式-CSDN博客https://blog.csdn.net/anlog/article/details/135338624
特此记录
anlog
2024年1月5日