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日

相关推荐
Scout-leaf1 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m6251 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#
Artech1 天前
[MAF预定义的AIContextProvider-02]AgentSkillsProvider——将Agent Skills引入MAF
ai·c#·agent·agent skills·maf
2601_962072552 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
m0_547486662 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
叶帆2 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
IT方大同2 天前
(嵌入式操作系统)信号量
嵌入式硬件·c#
z落落2 天前
C# FileStream文件流读取文件
开发语言·c#
yngsqq2 天前
排版优化 异形排版
c#
苦学的罐头2 天前
C# 协变与逆变深度解析:为什么 IEnumerable<T> 能转换,而 List<T> 不行?
开发语言·c#·list