Why are RAM module capacities in powers of two (512 MiB, 1, 2, 4, 8 GiB)?
Newer computers usually have 2, 4, 8, etc. GiB of RAM. The older ones usually have 128, 256, 512 MiB or less but also in powers of two.
What is the reason behind this? Why don't hard disks and DVD discs follow this norm?
Memory is closely tied to the CPU, so making their size a power of two means that multiple modules can be packed requiring a minimum of logic in order to switch between them; only a few bits from the end need to be checked (since the binary representation of the size is 1000
...0000
regardless of its size) instead of many more bits were it not a power of two.
Hard drives are not tied to the CPU and not packed in the same manner, so exactness of their size is not required.
Simply speaking, computers work in 1s and 0s. That's what binary is. The computer uses this system to address memory. In a simple (read "ancient") system, a certain number of processor lines or memory address unit lines are dedicated to selecting the address of a particular location in memory. Since those lines can only carry values of "high" or "low" each line represents a binary digit. So the number of locations that can be addressed is two to the power of the number of lines.
There is a correspondence between this and the address registers in the processor. Two to the number of bits in the register is the number of locations that can be addressed.
As memory sizes increased and computers became more powerful, a number of schemes have been employed to extend this capability and work around various limitations.
Please note that this overview is a greatly simplified look at a complex subject.
Also see the Wikipedia article on Memory addressing.
The binary system is known as base 2 because there are two possible values: 0 and 1 (on and off, high and low, 5V and 0V), compared to the normal natural number system known as base 10 (0-9). Hard drive manufacturers want their capacity to appear higher, so a 1GB drive (base 10, 1 billion bytes, 109) is really only 0.9313GiB (base 2, 2something) (this is also the reason for the disparity between what the computer reports and what the box says). The same is true for DVD discs.