- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 c 中创建无符号整数和 4 字节数组的 union 时,字节的顺序似乎颠倒了。这是为什么?
对于二进制表示的整数 10000000 00000000 00000000 00000000,我希望 b[0] = 10000000,b[1] = 00000000 等等。
#include <stdio.h>
#include <stdlib.h>
typedef union intByteRep{
unsigned int i; // 00000000 00000000 00000000 00000000
unsigned char b[4]; // b[0] b[1] b[2] b[3] - What we would expect
// b[3] b[2] b[1] b[0] - What is happening
} intByteRep;
char *binbin(int n);
int main(int argc, char **argv) {
intByteRep ibr;
ibr.i = 2147483648; // 10000000 00000000 00000000 00000000
for(int i = 0; i < 4; i++){
printf("%s ", binbin(ibr.b[i]));
}
printf("\n"); // prints 00000000 00000000 00000000 10000000
for(int i = 3; i >= 0; i--){
printf("%s ", binbin(ibr.b[i]));
}
printf("\n"); // prints 10000000 00000000 00000000 00000000
return 0;
}
/*function to convert byte value to binary string representation*/
char *binbin(int n)
{
static char bin[9];
int x;
for(x=0; x<8; x++)
{
bin[x] = n & 0x80 ? '1' : '0';
n <<= 1;
}
bin[x] = ' ';
return(bin);
}
最佳答案
因为你的系统是小端。
32 位整数 0x11223344
存储在内存中 0x44 0x33 0x22 0x11
在大端系统上它会被存储为:0x11 0x22 0x33 0x44
顺便说一句,大多数流行的 uP 都是小端。
关于c - 为什么它看起来像数组在 c union 体中反向索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55800153/
我正在尝试执行 vagrant up 但一直遇到此错误: ==> default: IOError: [Errno 13] Permission denied: '/usr/local/lib/pyt
我在容器 div 中有一系列动态创建的不同高度的 div。 Varying text... Varying text... Varying text... Varying text.
通过 cygwin 运行 vagrant up 时遇到以下错误。 stderr: /bin/bash: /home/vagrant/.ansible/tmp/ansible-tmp-14872260
今天要向小伙伴们介绍的是一个能够快速地把数据制作成可视化、交互页面的 Python 框架:Streamlit,分分钟让你的数据动起来! 犹记得我在做机器学习和数据分析方面的毕设时,
我是 vagrant 的新手,正在尝试将第二个磁盘添加到我正在用 vagrant 制作的虚拟机中。 我想出了如何在第一次启动虚拟机时连接磁盘,但是当我关闭机器时 然后再次备份(使用 'vagrant
我是一名优秀的程序员,十分优秀!