c# windows10大小端试

测试代码:

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日

相关推荐
习明然10 小时前
我的本地化AI项目(三)
人工智能·python·electron·c#·avalonia
范小多17 小时前
C#获取和风天气数据
java·开发语言·python·c#
z落落17 小时前
C# Task WaitAll、WaitAny、WhenAll、WhenAny
开发语言·c#
玖玥拾19 小时前
C# 语言进阶(十四)Unity UI界面开发 + 网络消息联动
服务器·开发语言·网络·ui·unity·c#·游戏引擎
czhc114007566320 小时前
712:Atta. cursor;ToggleButton
c#
玖玥拾21 小时前
C# 语言进阶(十三)网络 DLL 库分层设计
服务器·开发语言·网络·网络协议·c#
雪靡1 天前
WPF PerMonitorV2 下的跨窗口问题
c#·wpf
苍狼唤1 天前
SQL+C# 增删改查(练习)
数据库·sql·c#
LibraJM1 天前
一种适合程序员的 Agent 协作方式的实践
c#·copilot·agents