views:

21

answers:

1

Can you tell by looking at them which of these addresses is word aligned?

0x000AE430
0X00014432
0X000B0737
0X0E0D8844

A: 

The short answer is, yes. But you have to define the number of bytes per word. Some architectures call two bytes a word, and four bytes a double word. In any case, you simply mentally calculate addr%word_size or addr&(word_size - 1), and see if it is zero. When the address is hexadecimal, it is trivial: just look at the rightmost digit, and see if it is divisible by word size.

For a word size of 4 bytes, second and third addresses of your examples are unaligned. Second has 2 and third one has a 7, neither of which are divisible by 4. For a word size of 2 bytes, only third address is unaligned.

Dysaster