Little Endian 与 Big Endian

理解计算机中数据的字节序

什么是字节序(Endianness)?

字节序指的是多字节数据(如整数、浮点数)在内存中存储时,字节的排列顺序。 主要有两种方式:Little Endian(小端序)Big Endian(大端序)

Little Endian(小端序)

在 Little Endian 中,低位字节 存储在内存的低地址处。 例如,32 位整数 0x12345678 在内存中的存储顺序为:

地址增长方向 →
[0x78] [0x56] [0x34] [0x12]
      

现代 x86 和 x86-64 架构的 CPU 通常使用 Little Endian。

Big Endian(大端序)

在 Big Endian 中,高位字节 存储在内存的低地址处。 同样的数值 0x12345678 的存储顺序为:

地址增长方向 →
[0x12] [0x34] [0x56] [0x78]
      

许多网络协议(如 TCP/IP)采用 Big Endian,也称为“网络字节序”。一些处理器架构(如 PowerPC、SPARC)默认使用 Big Endian。

如何判断当前系统是哪种字节序?

可以通过以下 JavaScript 代码简单检测浏览器运行环境的字节序:

function isLittleEndian() {
  const buffer = new ArrayBuffer(2);
  const view = new DataView(buffer);
  view.setInt16(0, 0x1234, true); // 强制小端写入
  return new Uint8Array(buffer)[0] === 0x34;
}

console.log(isLittleEndian() ? 'Little Endian' : 'Big Endian');

注意:JavaScript 运行在浏览器中,而浏览器通常运行在 Little Endian 系统上,因此结果多为 Little Endian。

为什么字节序重要?

如何快速去除AI生成文章的痕迹 | 去AI味专业指南 格子达AIGC怎么降重?掌握这些方法,轻松降低AI检测率 朱雀检测可每日查重吗?AIGC检测每日次数与降重攻略 论文AIGC有必要检测吗?深度解析与实用指南 本科AIGC检测会倒查吗?全面解析与应对指南 | 论文查重与AI检测 It's Predicted That – Exploring Future Forecasts and Trends 安东尼·戴维斯篮球卡收藏指南 | 球员卡介绍与价值分析 All Their Own – A Simple Reflection “Pack Up Things”中文翻译及用法详解 kisstherain简谱完整版 - 钢琴曲《Kiss The Rain》简谱下载与欣赏 Is That It? – A Simple Reflection Paytend 官网下载 - 安全可靠的支付终端软件 the rain 小提琴曲 - 纯净音乐欣赏 Anthony Bowie - Former NBA Player and Basketball Enthusiast Stay Up Doing Something – 保持清醒,专注热爱 Running in the Dark - 在黑暗中奔跑 Intend - 理解意图与目的 “Stay Up Doing” 的中文含义与用法解析 Had It Been 虚拟语气用法详解 - 英语语法专题 Chick In - 小鸡的温馨世界 thinking怎么读英语 - 英语发音指南 It Is Announced That – Official Announcement Portal It's Hard To... — 面对困难时的思考与坚持 “on the instant” 与 “in an instant” 的区别与用法 想象力的力量 | 探索创造力的源泉 Thinking英文怎么读 - 发音、音标与例句详解 Running Up That Hill 歌词 - Kate Bush Check In / Check Out 管理指南 | 简洁实用的签到签退说明 attenda - 简洁高效的活动管理工具 Make Things Up - 激发创意,从想象开始 Please Stand By - 系统维护中 Heartbroken 与 Heartbreaking:情感的两种表达 “pack sth up” 造句示例与用法解析 A Give and Take:给予与接受的平衡之道 But We Were Surprised That Ninety Percent of Them 积极思考,感受美好 - 培养正向心态的简单指南 Pack It Up - 简单实用的打包指南 Walking Down the Street 歌词 - 简洁歌词页面 Breath In - 专注呼吸,回归平静 It Takes S.B. Time to Do Sth — 关于时间、行动与坚持的思考 Pack Up Your Things - 简单整理与打包指南 attain变形详解 - 英语动词变形规则与用法 Student.KooBits - 学生学习平台 Kiss the Rain 创作背景 - 钢琴曲背后的故事 说易行难 - To Say Is Easier Than To Do “at the end”和“in the end”有什么区别?英语短语辨析 Had It - 简约生活与内心感悟 “the instant that”造句示例与用法解析 如何打包物品(Pack Something Into) - 实用指南 如何打包物品 - 实用打包指南 Critical Thinking 举例 - 培养批判性思维的实际案例 It takes sb to do sth 句型讲解 - 英语语法专题 雨势正浓 - 静听大雨倾盆的声音 attend造句示例 - 英语学习资源 Stay Up Doing - 简洁待办事项与专注记录 “it has not”的缩写是什么?常见英文缩写解析 Hit the Nail on the Head 课件 | 英语习语学习 Pay Attention to Doing 例句详解 | 英语语法学习 Run Up the Road – 奔跑在路上的旅程 爱称与亲昵语 - Endearment 专题 “spend…with”后面接什么?常见搭配与用法详解 专注力:Attention to Doing 的实践与意义 Walking Down the Street - 漫步街头的宁静与思考 Instant咖啡 - 快速冲泡,醇香随享 IT is said that — 探索科技与编程的智慧箴言 accidentally 音标 - 英文单词发音与释义 It's Hard To – 探索那些难以言说的时刻 用“pack up things”造句 - 英语学习例句 Power Packed Into – Simple & Efficient Solutions It is hard for sb to do sth — 英语句型解析与用法指南 Kiss The Rain 伴奏 - 雨的印记钢琴曲纯音乐下载与欣赏 Walk Up and Down - 漫步上下,感受节奏与风景 Has It Been? — Explore Historical and Current Events During Last – Reflections on Recent Times 若非如此 —— “if it hadn't been for” 用法详解 签到与签退 - 简洁打卡工具 packupthings 翻译 - 中文含义与使用指南 “The Final”翻译与解析 - 中文含义详解 despite 和 although 的区别 | 英语语法详解 despite the fact that 用法详解 | 英语语法学习 Die For You - The Weeknd | Song Overview 英语泛读与批判性思维 | 提升阅读理解与思辨能力 Destination 的中文含义与用法详解 Interpal下载 - 官方安全下载页面 What Is His Head? – Understanding the Phrase and Its Meanings in head of — 探索思想与意识的源头 Running Up That Hill 歌曲介绍 - Kate Bush 经典作品 By an Accident - 一次意外的故事 It Is Evident That – Exploring Obvious Truths and Clear Facts Pack Up the Things – Simple Guide to Packing Efficiently 事故预防与应对指南 - 安全知识专题 “It is announced that”造句示例与用法解析 It is hard to 造句示例与用法解析 His Head - 探索思想与意识的起点 It Rained Hard – A Moment in the Storm “Take it for granted”的用法详解 | 英语短语学习 心跳加速:探索心悸的原因与应对方法 How Nice Weather – Enjoy the Beauty of Clear Skies and Sunshine Running Up at That Hill – A Journey of Perseverance With Something Doing:探索伴随行为的表达方式 nightnight翻译 - 简洁可靠的夜间问候语翻译工具 Chinatown Market - Explore Authentic Asian Goods The Remaining – Reflections on What Endures Weather Permitting – Exploring Life’s Plans and Nature’s Will It Has Been 句型详解 - 英语语法学习