I ran into this question in class: Assume a machine that is 64-bit and has 8GB memory. They use a paged virtual memory where the page size is 4KB. You run the following program:

int main() {
   int *ptr = malloc(16);
   printf("%p\n", ptr);
   return 0;

and get output: 0x555555756260

We're to find the virtual page number of the address and the offset.

What I'm thinking is that I first convert that to binary, figure out how many bits and which bits represent the address/offset.

But I'm not sure how to figure out the latter. How can I determine which bits in the address correspond to which?

I'd really love some guidance

  • $\begingroup$ 4K is $2^{12}$. Each hex digit represents four binary ones. $\endgroup$
    – greybeard
    Apr 7, 2021 at 3:19
  • $\begingroup$ @greybeard how do I find out which hex digits correspond with the page number and the offset? Like is the offset the last 24 bits or...? $\endgroup$
    – Melanie
    Apr 7, 2021 at 4:41
  • $\begingroup$ This question most probably came up in some environment introducing into implementation of computers (using electronic circuitry for now). It would seem time to revisit whatever material there is on paged memory. While the offset is in the less significant part, even with bit addressable memory it would not take 24 bits to identify one cell in a 4KB page. $\endgroup$
    – greybeard
    Apr 7, 2021 at 7:47

2 Answers 2

  • assume address printed out to be a "byte address"
  • guess whether the offset to find is addressable unit in page or byte in page
    • if addressable unit in page, figure out its size
      with nothing more than 64-bit to go on a first assumption is 8 bytes
  • guess the representation wanted for virtual page number & offset

(Base conversions in the process depend on practice with the representations involved. For a result in hex, too, some would prefer to just double (word offset) or halve ("byte page#") "in hex". A coder might have a program print both parts before even considering if coding the task was least effort.)

  • $\begingroup$ For a bonus of 4 rubber points: What has the amount of memory been specified for? $\endgroup$
    – greybeard
    Apr 7, 2021 at 9:45

Rather than converting to binary, it is more convenient to convert the page size to hexadecimal ($\text{0x10000}$). This hints you which are the significant hex-digits in the address.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.