TAOCP 2.5 Exercise 23

A block of size $4$ contains addresses that differ only in the last two bits.

Section 2.5: Dynamic Storage Allocation

Exercise 23. [**] [05] What is the binary address of the buddy of the block of size 4 whose binary address is 011011110000? What would it be if the block were of size 16 instead of 4?

Verified: yes
Solve time: 1m07s


A block of size $4$ contains addresses that differ only in the last two bits. Therefore the buddy is obtained by complementing the bit immediately to the left of those two bits, namely the third bit from the right. For

$011011110000,$

the third bit from the right is $0$; changing it to $1$ gives

$011011111000.$

Hence the buddy address is

$\boxed{011011111000}.$

If the block size is $16=2^4$, the last four bits specify positions within the block. The buddy is obtained by complementing the fifth bit from the right. In

$011011110000,$

that bit is $1$; changing it to $0$ gives

$011011010000.$

Hence the buddy address in this case is

$\boxed{011011010000}.$