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"));
        }
    }
}

输出结果

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日

相关推荐
xiaowu08012 小时前
策略模式-不同的鸭子的案例
开发语言·c#·策略模式
VisionPowerful15 小时前
九.弗洛伊德(Floyd)算法
算法·c#
ArabySide15 小时前
【C#】 资源共享和实例管理:静态类,Lazy<T>单例模式,IOC容器Singleton我们该如何选
单例模式·c#·.net core
gc_229917 小时前
C#测试调用OpenXml操作word文档的基本用法
c#·word·openxml
almighty2720 小时前
C#海康车牌识别实战指南带源码
c#·海康车牌识别·c#实现车牌识别·车牌识别源码·c#车牌识别
c#上位机1 天前
wpf之TextBlock
c#·wpf
almighty271 天前
C# WinForm分页控件实现与使用详解
c#·winform·分页控件·c#分页·winform分页
almighty271 天前
C#实现导入CSV数据到List<T>的完整教程
c#·csv·格式转换·c#导入数据·csv数据导入
程序猿多布1 天前
Lua和C#比较
c#·lua
csdn_aspnet2 天前
使用 MongoDB.Driver 在 C# .NETCore 中实现 Mongo DB 过滤器
mongodb·c#·.netcore