小端和大端 [英] Little-endian and Big-endian

查看:73
本文介绍了小端和大端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个例程以在两种表示形式之间进行转换。
但是我有点困惑。
如果我有一个具有32位字的内存的结构
,并且必须使用Big-endian存储字0xA15D23B1
,则该内存在23天之后的5D之后到最后的B1 $变成A1。 b $ b和Little-endian相比,内存在5D之后的23之后和A1之后的内存是B1
是吗?

I must write a routine for conversion between the 2 representations. But I'm a bit confused. If I have an architecture with a memory with words of 32 bits and I must store the word 0xA15D23B1 with Big-endian the memory become A1 after 5D after 23 and in the end B1 with Little-endian rather the memory is B1 after 23 after 5D and after A1 Is it right?

如果我可以寻址机器上的各个字节,并且字的地址为零
谁是字节1?
在Big-endian中是5D吗?而且在little-endian中也是5D吗?

If I can address the individual bytes on my machine and the address of my word is zero who is the byte 1? In Big-endian is 5D? and in little-endian is 5D too?

感谢所有会回答我的人

推荐答案

大端存储布局首先是最高有效字节,而小端存储布局首先是最低有效字节。给定值0xA15D23B1:

Big-endian memory layout is most significant bytes first, whereas little-endian layout is least significant bytes first. Given the value 0xA15D23B1:

Memory address    0  1  2  3
Big-endian       A1 5D 23 B1
Little-endian    B1 23 5D A1

请注意,大尾数存储布局字长不会改变,但是小尾数会改变。如果考虑两个短字(16位),则连续存储0xA15D和0x23B1:

Note that big-endian memory layout does not change with respect to word size, but little-endian does. If you consider two short words (16 bit), 0xA15D and 0x23B1 stored contiguously:

Memory address    0  1  2  3
Big-endian       A1 5D 23 B1
Little-endian    5D A1 B1 23

这篇关于小端和大端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆