It's not 32 bits, it's 5 bits.
The number 32 is 0x00000020.
31 is 0x0000001f.
~31 is 0xffffffe0.
So & 31 gives you the lower 5 bits.
& ~31 gives you all bits except with the lower 5 bits turned off.
The code appears to be getting the block number of one 32-byte block larger than the upper address of a RAM chip. I get that from the part where it adds 31 and then divides by 32.