: Hi this is a really simple question, but I'm in a rush to finish a project which just doesn't seem to want to work, so I decided to ask here. I need to know how to check if a given memory address is double-word aligned - basically as an error checking routine. I'm ok with the actual programming part, just wondering what the process/logic behind this would be. I had an idea but it didn't seem to work...so rather than embarass myself with my lack of knowledge by saying more, I just wonder if anyone here can help me at all. I can give more detail if necessary.<br>
: Thank you :)<br>
: <br>
<br>
<br>
Ok, I don't know what language to go for, but I'll just use C. <br>
<br>
The logic behind it is the address is a multiple of 4. IE address modulus 4 equals 0.<br>
<br>
Since 4 is a power of two and addresses are unsigned you can use a shortcut to speed up the code by anding the value with 3.<br>
<br>
so to check just do (in C) &var&3 which actually works out perfectly for you. It will be 0 (zero) if it is aligned (which is false) and not 0 (true) if it isn't so you can do the following...<br>
<br>
if(&var&3){<br>
//handle unaligned stuff here.<br>
}<br>
<br>
have fun.<br>
<br>