【发布时间】:2015-10-29 20:34:20
【问题描述】:
在 C++ 中连接两个十六进制值时遇到问题;
int virtAddr = (machine->mainMemory[ptrPhysicalAddr + 1] << 8) | (machine->mainMemory[ptrPhysicalAddr]);
int physAddr = currentThread->space->GetPhysicalAddress(virtAddr);
对于machine->mainMemory[ptrPhysicalAddr + 1],这将产生0x5。对于machine->mainMemory[ptrPhysicalAddr],这将产生0x84。我期待结果0x584。但是,我收到了0xffffff84。我关注了这个问题Concatenate hex numbers in C。
【问题讨论】:
-
size_t 和 ptrdiff_t 是你想要的类型
-
mainMemory的类型是什么? -
@AlanStokes 它是一个字符数组
标签: c++ hex bit-manipulation