views:

86

answers:

4

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.

+3  A: 

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

jalf
Thank you for the straight forward answer.
Frank V
A: 

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.

Mehrdad Afshari
Shouldn't it be `ln(x)/ln(a)`?
Bastien Léonard
I did indeed admit that it is a borderline question, but it is computer science related. Others may need this information.
Frank V
It works for any base of logarithm. ln is just using Euler's constant e as the base.
Chris Simmons
@Chris: thanks, it seems obvious now. I still think that the natural logarithm is more, well, natural.
Bastien Léonard
A: 

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).

Martin v. Löwis
+2  A: 

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.

lavinio
It does help, thank you.
Frank V