Content deleted Content added
No edit summary |
Peter Flass (talk | contribs) →Computing padding: note on byte/word sizes |
||
Line 86:
For example, the padding to add to offset 0x59d for a 4-byte aligned structure is 3. The structure will then start at 0x5a0, which is a multiple of 4. However, when the alignment of ''offset'' is already equal to that of ''align'', the second modulo in ''(align - (offset mod align)) mod align'' will return zero, therefore the original value is left unchanged.
Since the alignment is by [[#Definitions|definition]] a power of two<ref>On modern computers where the target alignment is a power of two. This might not be true, for example, on a system using 9-bit bytes or 60-bit words.</ref>, the modulo operation can be reduced to a bitwise boolean AND operation.
The following formulas produce the aligned offset (where ''&'' is a [[bitwise AND]] and ''~'' a [[bitwise NOT]]):
|