How to determine if an address matches a word

Can you tell us which of these addresses are word aligned?

0x000AE430
0X00014432
0X000B0737
0X0E0D8844

+3
source share
1 answer

The short answer is yes. But you must determine 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_sizeor addr&(word_size - 1)and see if it is equal to zero. When the address is hexadecimal, this is trivial: just look at the rightmost digit and see if it is divided by the size of the word.

4 . 2 7, 4. 2 , .

+12

Source: https://habr.com/ru/post/1769312/


All Articles