A computer has 256MB of memory.
Each word in this computer is 16 bytes.
How many bits are needed to address each word in memory?

Dani AI

Generated

A small, reliable way to think about this problem: first decide what one address selects (a byte or a word). Then count how many of those addressable units exist, and finally pick the smallest integer b such that 2**b is at least that count. In formula form:

bits = ceil(log2(number_of_addressable_units))

If addresses select bytes, number_of_addressable_units = total_bytes. If addresses select words of W bytes, number_of_addressable_units = ceil(total_bytes / W).

Common gotchas to keep in mind:

  • The meaning of "MB" can be decimal (1,000,000) or binary (2**20). Use the interpretation the question expects.
  • CPU address width (how many address lines exist) can be larger than the amount of installed memory; questions sometimes ask about installed memory, sometimes about the architecture's address space.
  • Alignment/endianness do not change the count of address bits; they only affect how those addresses map to bytes in memory.

A compact Python helper (adjust total_bytes and unit_bytes as needed):

import math

def address_bits(total_bytes, unit_bytes=1):
    units = (total_bytes + unit_bytes - 1) // unit_bytes
    return math.ceil(math.log2(units))

As noted, the addressing scheme matters; demonstrated the arithmetic in the thread; 's short reply looks like a misread rather than a full calculation.

Recommended Answers

All 3 Replies

Is this a trick question?

(The answer depends on the machine's addressing scheme ;) )

3.

A computer has 256MB of memory.
Each word in this computer is 16 bytes.
How many bits are needed to address each word in memory?

Assuming by 256MB you mean 2^28, you'd need 28 bits to address all the bytes; to address only words, you'd need (2^28)/16 = (2^28)/(2^4) = 2^24, or 24 bits.

However, the number of bits needed really depends on how much memory the computer _could_ have, not what it happens to have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.