0
我试图得到一个数字是16位数字长0x1122334455667788和位移它来说明小端编号。uint64_t在C充当uint32_t
使用下面的示例代码从存储单元加载数
void endianCompute(memory_t memory, uint64_t start, uint64_t *save, int size){
*save = 0;
for(int i = 0; i < size; i++){
*save += memory[start + i] << (i)*8;
printf("add 0x%x\n", memory[start + i] << (i)*8);
printf("save 0x%x\n", *save);
}
}
的输出产生:
save 0x88
add 0x7700
save 0x7788
add 0x660000
save 0x667788
add 0x55000000
save 0x55667788
add 0x44
save 0x556677cc
add 0x3300
save 0x5566aacc
add 0x220000
save 0x5588aacc
add 0x11000000
save 0x6688aacc
这对我来说很有意义,直到加0×44,为什么位转移不会继续将数字推向左侧?为什么我无法输入过去8位数字的号码?
什么是'memory_t'?另外,你的'save'行会在你的'add'行之前打印出来? – yano
为了打印'uint64_t',你需要一个不同的格式说明符,比如'%llx'。 –
打开编译器警告。 – Schwern