So I am looking at some Operating Systems exercises and we have

A swapping system eliminates holes by compaction. Assuming a random distribution of many holes and many data segments and a time to read or write a 32-bit memory word of 10 nsec, about how long does it take to compact 128 MB? For simplicity, assume that word 0 is part of a hole and that the highest word in memory contains valid data.

The solution is : 128 x 2^20 / 4 = 2^25 memory address

      compaction time = (read + write) * # of memory access
                      = 2 x 10 x 10 ^ -9 x 2^25
                      = 671 ms

Problem is I dont understand the 128 x 2^20 / 4 = 2^25 memory address part ? How did we get 2^20 in this case? I gues the 4 is 4 bytes =32 bits so I kinda understand that.

Now in 2 x 10 x 10 ^ -9 x 2^25 what is 2 here?

  • $\begingroup$ Note that you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction. $\endgroup$
    – Raphael
    Commented Feb 26, 2016 at 15:22

1 Answer 1


A megabyte is $2^{20}$ bytes.

The factor of $2$ is because we need to count both reads and writes.

  • $\begingroup$ Sorry but a megabyte is 1024 bytes which is 2^10 bytes..why 2^20 bytes? $\endgroup$
    – Jane D.
    Commented Feb 26, 2016 at 14:11
  • $\begingroup$ No, a kilobyte is $2^{10}$ bytes. A megabyte is $2^{20}$ bytes, a gigabyte is $2^{30}$ bytes, a terabyte is $2^{40}$ bytes, and a petabyte is $2^{50}$ bytes. All of this information can be found online. Please make more effort next time. When something doesn't make sense, sometimes there is an error, and at other times the mistake is yours. In cases like this it is very easy to find out. No need to trouble us here. $\endgroup$ Commented Feb 26, 2016 at 14:14
  • $\begingroup$ See the table on the top right for the source of the confusion. $\endgroup$
    – G. Bach
    Commented Feb 26, 2016 at 15:16

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.