Lets say a system has 1TB of memory and 4kB blocks. How many MB of memory do we need if we want to store a bitvector to represent the current memory allocation situation with a bitvector?

Bitvector: a string of concatenated 0s and 1s, where 0 means a block is free, 1 means it is already allocated.

The solution is given as 256MB, but I get a completely different number:

1TB = 1000000000 kB 1000000000/4 = 250000000 Blocks Each block can be represented as 1 bit, thus we need 31.25 MB

Where am I wrong?


1 Answer 1


Well, let's get the radix right. 1TB is $2^{40}$ bytes, and 4kB is $4\times 2^{10}$ bytes. So the number of blocks is:

$$\frac{2^{40}}{2^{12}} = 2^{28}$$

There are $2^3$ bits in a byte, so that's $2^{25}$ bytes to represent the bit vector, or 32MB.

The ratio between the two, of course, is exactly 8, which makes me think that they didn't take the number of bits in a byte into account.

  • 1
    $\begingroup$ Thank you very much for your clear explanation. This makes me more confident that the solution I was given is incorrect. $\endgroup$ Commented Jun 5, 2022 at 19:45

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.