[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
首先,计算机系统中内存是以字节为单位进行编址的,每个地址单元都唯一的对应着1个字节(8 bit),这也可以应对 char 类型数据的存储要求,因为 char
类型在内存中占1个字节,但是有些类型的长度是超过1个字节的(字符串虽然是多字节的,但它本质是由一个个 char 类型组成的类似数组的结构而已),比如 int
类型一般4个字节,short 类型一般是2个字节等等。
所以就存在着多个字节数据中各字节存放顺序的问题。正是因为不同的排放顺序,才有了大端字节序存储和小端字节序存储方式的存在。
例如:
int main() { int W = 0xaabbccdd; // // 这里初始化 W 为 0xaabbccdd (十六进制的数) //
一个16进制位是4个二进制位,所以2个16进制位是8个二进制位也就是1个字节 // 那么 aa、bb、cc、dd 都各占1个字节,一共占四个字节 //
那4个字节在内存中存储就有顺序了 return 0; }
大端字节序存储:把一个数据低位字节处的数据存放在高地址处,把高位字节处的数据存放在低地址处。
那么 0xaabbccdd 在内存中以大端字节序存储就为:
小端字节序存储:把一个数据高位字节处的数据存放在高地址处,把低位字节处的数据存放在低地址处。
那么 0xaabbccdd 在内存中以小端字节序存储就为:
那么自己电脑上的是怎么存储的?我用自己的VS2019来示范一下:
所以我的VS是用小端字节序存储的,可以自己动手看一下自己的是不是也是小端存储。