Big-endian/Little-endian, LSB/MSB
Least significant byte (LSB) Most significant byte (MSB)
Big-endian machines store the most-significant byte at the lowest-numbered address, with the other bytes following in decreasing order of significance. Little-endian machines store multi-byte numbers in the opposite order: from least-significant to most-significant.
Internet diagram is big-endian. STM32 ARM-CM3 is little-endian.
这是从wiki的Example

如何用简单的方法检查是大端还是小端
uint8_t IsBigEndian(void)
{
volatile uint32_t temp = 0x0a0b0c0d;
return (*((uint8_t*)(&temp))) == 0x0a;
} void EndianTest(void)
{
if (IsBigEndian() == )
{
std::cout << "it is a big-endian" << std::endl;
}
else
{
std::cout << "it is a little-endian" << std::endl; }
}
从调试也可以看出内存地址和值, 注意0x0a是most-significant byte。

字节顺序其实就是说在计算机内存中怎么存储,是说从左到右,还是从右到左。对于在一个机器内的数据交互,那种字节顺序都没有关系。主要的问题是在不同机器上交互,比如你设计一个总线系统,那么你就要充分考虑你的通讯协议使用大端还是小端。比如说TCP/IP协议它就是是按照big-endian来设计的,因为你不知道网络系统的电脑,路由器,等等的字节顺序,所以在设计通讯协议时就要充分考虑到这一点。
在TCP/IP里有一系列的函数用于字节的转换如htons (covert host byte to network byte short 16bit), htonl (convert host byte to network byte long 32bit), ntohs (network byte to host byte short 16bit), ntohl (convert network byte to host byte long 32bit). 当你设计通讯协议时,这些函数你就要自己实现了。
说到TCP/IP,让我想起一个我们以前遇到的一个问题,我们的panel在客户那里每个星期二凌晨都会自动重启。后来分析是由于客户每个星期二IT部门会用nmap进行扫描,而TCP/IP字节数的问题造成系统死了,后由Watchdog重启。我把以前分析的一些简要内容放在这里(只有英语版)。
Problem Description
The field reports show that panel will lockup and then reboot while doing security port scan by nmap.
Root Cause
After analysis, this problem happens at all panel versions, standalone/networking panel, and happens at other scanning tools (e.g. Tenable Nessus).
The investigation shows that, the problem was caused by unaligned data access during TCP timestamps option parsing in Linux kernel. The reason can be summarized below:
1) The ARMv5 or earlier MCU (likes panel MCU S3C44B0X ARM7TDMI is belong to ARMv4T), who had limited abilities to access memory that was not aligned on a word (four byte) boundary. According to S3C44B0 datasheet (see page 89 Address Alignment), the MCU is going to ABORT mode which cause the system crash.
2) In Linux TCP option parsing, the handling did not consider the data unaligned in timestamp option, but TCP options are not guaranteed to be aligned at all.
According to the Linux debug output information when TCP package with timestamps options: The timestamps hold address (register: R8) is 0x0DB074E2, which is not multiple 4(word), the Linux kernel error information is: Unhandled fault: alignment exception (13).
1) TCP package by nmap

2) Linux debug output

Solution
The solution is get word value byte one byte when the address is unaligned, which is come from official Linux kernel patch (see appendix). The change is only applied for TCP/IP option parsing and without side effect. The solution had been successfully verified by prototype.
Purpose: for field panels, firmware upgraded is the recommended solution if the panel was be connected to internet or corporate network, and it is not need to upgrade firmware if the panel was not be connected to network.
Appendix
The patch is come from Linux official, the link is https://archive.org/details/git-history-of-linux.

Big-endian/Little-endian, LSB/MSB的更多相关文章
- MSB与LSB Big Endian Little Endian
Most Significant Bit, Last(Least) Significant Bit 最高有效位(MSB) 指二进制中最高值的比特.在16比特的数字音频中,其第1个比特便对16bit的字 ...
- 彻底搞懂字符编码(unicode,mbcs,utf-8,utf-16,utf-32,big endian,little endian...)[转]
最近有一些朋友常问我一些乱码的问题,和他们交流过程中,发现这个编码的相关知识还真是杂乱不堪,不少人对一些知识理解似乎也有些偏差,网上百度, google的内容,也有不少以讹传讹,根本就是错误的(例如说 ...
- LSB MSB
#LSB:(Least Significant,Bit) 最低有效位 :MSB(Most Significant Bit):最高有效位,若MSB=1,则表示数据为负值,若MSB=0则表示数据为正. 在 ...
- 低字节序和高字节序相互转换(Little Endian/Big Endian)
这个例子展示了如何转换整形数字的字节顺序,该方法可以用来在little-endian和big-endian之间转换. 说明:Windos(x86,x64)和Linux(x86,x64)都是little ...
- 关于Big Endian 和 Little Endian
Big Endian 和 Little Endian 一.字节序 来自:http://ayazh.gjjblog.com/archives/1058846/ 谈到字节序的问题,必然牵涉到两大CPU派系 ...
- 清晰讲解LSB、MSB和大小端模式及网络字节序
时隔一个月又回到了博客园写文章,很开心O(∩_∩)O~~ 今天在做需求的涉及到一个固件版本的概念,其中固件组的人谈到了版本号从MSB到LSB排列,检索查阅后将所得整理如下. MSB.LSB? MSB( ...
- 字符编码笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian
转载:http://witmax.cn/character-encoding-notes.html 今天中午,我突然想搞清楚Unicode和UTF-8之间的关系,于是就开始在网上查资料. 结果,这个问 ...
- 06socket编程
socket可以看成是用户进程与内核网络协议栈的编程接口. socket不仅可以用于本机的进程间通信,还可以用于网络上不同主机的进程间通信. IPv4套接口地址结构通常也称为“网际套接字地址结构”,它 ...
- UNIX网络编程——socket概述和字节序、地址转换函数
一.什么是socket socket可以看成是用户进程与内核网络协议栈的编程接口.socket不仅可以用于本机的进程间通信,还可以用于网络上不同主机的进程间通信. socket API是一层抽象的网络 ...
随机推荐
- VSTO:使用C#开发Excel、Word【10】
第二部分:.NET中的Office编程本书前两章介绍了Office对象模型和Office PIA. 您还看到如何使用Visual Studio使用VSTO的功能构建文档中的控制台应用程序,加载项和代码 ...
- SQL-1 选取表中某一属性最大值的所有信息 查找最晚入职员工的所有信息
题目描述 查找最晚入职员工的所有信息CREATE TABLE `employees` (`emp_no` int(11) NOT NULL,`birth_date` date NOT NULL,`fi ...
- centos7 安装jdk8 bash脚本 并配置环境变量
#!/bin/bash #安装java脚本 if type -p java; then echo 'java已安装.' exit else echo '开始安装java...' wget --no-c ...
- fk makefile文件的一些问题
除了要按具神说的makefile修改之外,还发现了另外一个问题: 不然就改成SACLIB=-L/usr/local/sac/lib
- 循环神经网络-LSTM
LSTM(Long Short-Term Memory)是长短期记忆网络,是一种时间递归神经网络,适合于处理和预测时间序列中间隔和延迟相对较长的重要事件. LSTM能够很大程度上缓解长期依赖的问题. ...
- L304 What Is Death?
How should we define the death of a person? Philosophers and physicians have long pondered this ques ...
- mysql ON DUPLICATE KEY UPDATE ; 以及 同replace to 的区别.
需求: 1)如果admin表中没有数据, 插入一条 2)如果admin表中有数据, 不插入. 一般做法: if($result = mysql_query("select * from ad ...
- Go Storm Is Coming!
goland---http://idea.youbbs.org .................................................................... ...
- Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException
Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException时,请Catch HibernateOptimisticLockingFailur ...
- prototype和_proto_
__proto__(隐式原型)与prototype(显式原型) 显式原型 explicit prototype property:用来实现基于原型的继承与属性的共享. 每一个函数在创建之后都会拥有一个 ...