1
$\begingroup$

I'm working on learning operating systems and I've come across a strange question that I don't know how to answer.

The question is:

Assuming a 1-KB page size, what are the page numbers and offsets for the following address references (provided as decimal numbers)?

21205

The notes and slides I have are very confusing and I can't find anything quite like this from my searches. I understand that a 1KB page size means that it's 2^10 but what do I do after that exactly? Most descriptions I see involve splitting that in half and using the first half as your offset and the other half as the page number but then I see others saying not to do this and my notes, as I mentioned, are useless. I'm sure this is extremely easy but I feel like I've been given only 1/3 of the knowledge needed.

Any help would be greatly appreciated!


Addendum

I took a step back for a little while and I think I realized where my confusion was coming from.

I determined that 21,205 is within the range of 2^15, so it's a fifteen bit number. If I subtract the size of the page (10) from the size of the number (15) then that should, in theory, give me a page number of 10 and an offset of 5.

The next bit is pure speculation on my part but I'm assuming that I then take the decimal form of 21,205, which is 101001011010101, and segment it accordingly. The first ten bits (1010010110) equals 662 and the last five bits (10101) equals 21. So my tentative answer is

Page Number = 662 & Offset = 21.

Is this at all reasonable or do I do it completely wrong?

$\endgroup$
0
$\begingroup$

I think Page numbers will be given by first 5 bits and last 10 bits will give the offset. With the first 5 bit first you locate which page no. you want to go and then remaining 10 bits will tell you the offset at that page taking you at the exact location

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

You are correct in thinking that you are completely wrong. What you need to do is forget all your notes and work everything out from first principles. That is the delight of maths (for example): there are no facts.

First, try an easier problem. Suppose you have a civilised computer with a 1000-byte page size. Then the address 21205 will be at page 21 (the first page is page 0) and the offset is 205.

Next, try to explain what you have just done in an unnecessarily complicated way. You got “21” not because it was obvious but because you laboriously calculated 21205÷1000. You got “205” not because it was obvious but because you took 21205 and worked out the remainder on dividing by 1000.

Next, take what you did in the last paragraph but instead of 1000 use 1024. You will get a page number and an offset and the answer to your question.

Finally, have an attack of laziness. Realise that you never needed to divide by 1000: you only needed to write down 21205 in decimal and cut off the last three digits. Realise that you never needed to take the remainder after division by 1000: you only needed to take the last three digits on their own.

So the finally final step is to replace “1000” by “1024”, “decimal” by “binary”, and “three” by “ten”.

And then, at last, you can look at your half remembered notes and see what you got wrong. It was a simple transposition - but there’s no point in correcting them because now you know why it all works, you can reinvent the formula yourself any time you want to.

The great thing about maths is that there are no facts.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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