Question

I have what might be more of a math question but this question is stemming from reading my computer systems book in the chapter on Virtual Memory... so I feel justified asking it here.

The book states:

Each virtual page is P = 2p bytes in size.

My algebra is rusty which is probably the reason I need to ask this. Now, for an example that I'm looking at, we know that P = 1024. Does this mean that I can figure out what p is by simply identifying which p will make

1024 = 2p
true?

If my epiphany is true and correct, then 1024 = 210 should be my answer. That is P=1024 and p=10.

Was it helpful?

Solution

yes. It's just an equation like any other.

OTHER TIPS

Yes.

In order to solve for p you need to use the logarithm function, base 2. Solving for

P = log(p, 2)

or

10 = log(1024, 2)

If you don't have a handy-dandy logarithm function available to you which lets you set the base, you can use this. Interestingly enough, it doesn't matter what log base you use in the two functions, as long as they are the same:

P = log(p) ÷ log(2)

Logarithms are the opposites of exponents - they are just a way to count the number of times you must multiply a number by itself to get the answer, extended to support cases where the answer isn't an integral power of the original number.

Hope this helps.

I think this question is on the borderline of not programming related but anyway, the inverse of f(x)=ax is g(x)=log(x)/log(a). You just need to get the base 2 logarithm of P=1024 to find p, which is 10.

What you are asking for is the binary logarithm (ld n). You compute it by repeatedly dividing by 2, breaking when you reach 1, and counting how often you have divided (that's actually just the integral part of it +-1, but for a power of two, the logarithm is a natural number).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top