Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Can you tell by looking at them which of these addresses is word aligned?
0x000AE430 0X00014432 0X000B0737 0X0E0D8844
简短的回答是,是的。但是您必须定义每个字的字节数。一些架构称两个字节为一个字,四个字节为一个双字。在任何情况下,您只需在心里计算addr%word_sizeor addr&(word_size - 1),看看它是否为零。当地址是十六进制时,它是微不足道的:只看最右边的数字,看看它是否可以被字长整除。
addr%word_size
addr&(word_size - 1)
对于 4 个字节的字长,示例的第二个和第三个地址未对齐。第二个有 2,第三个有 7,两者都不能被 4 整除。对于 2 字节的字长,只有第三个地址是未对齐的。