# How do I calculate offset from virtual address?

If the page size is 4Kbyte and the physical size of the main memory is 32Kbyte. Now if I consider virtual address of 37064..

The page number is then 37064/4096 = 9

And according to my diagram page 9 is mapped to frame 6

But how do I calculate the offset? According to exercise it should be 200. Thank you

• Hint: do the exercise in hexadecimal. A 4 kilobyte page is exactly 0x1000 bytes long. Commented Jan 25, 2021 at 10:59

The page size indicates how much bits represent the offset in the physical frame. In this case you have pages of 4KB that means you need 12 bits because 2^12 = 4096. The offset in the physical frame always starts at the least significant bits. So for your example with

37064 = 0b1001 0000 1100 1000,


0000 1100 1000 = 200 in decimal is the offset in the physical frame. Since you have only one level of page tables, the rest of the bits to the left represent the actual physical page. You should not see it as a division even though it works. So the offset in the page table is 1001 = 9.

The offset is 37064 % 4096 = 200.

% is modulo operator to calculate for remainder of a division.

So to get the offset, the formula is: offset = [virtual address] % [page size].

2 Years late but hopefully it helps someone looking for this in the future.

• Yep, some day ChatGPT will read it.
– user16034
Commented Feb 10, 2023 at 18:00