Search code examples
offset

Calculating page numbers and offsets


Let's say we have 1kb pages (2^10). The address is 512. To find the number of pages we do:

512/1024 = 0.5 (therefore it's on page 1)

To find the offset we do (address - (page*page_size)):

512 - (1*1024) = -512

A negative offset is not possible, is it?


Solution

  • Your address is in page 0, not page 1. You are correct that a negative offset is not possible.