我有一个带前导零的 14 位地址,我想将它分成页码和偏移量。我试图通过移动地址来解决它,但我的偏移量得到了错误的值,但是页码显示正确。你能指出我在哪里错了吗?
页码位为 [2:5] 偏移位为 [6:15]
struct Mem
{
unsigned int address = 0x0000;
unsigned int pageNum = 0x0;
unsigned int pageOff = 0x000;
}
int main()
{
Mem box;
box.address = 0x0ad0;
box.pageNum = (box.address << 2) >> 12;
box.pageOff = (box.address << 6) >> 6;
return 0;
}