IP Address CIDR Bitmask Conversion
The binary expansion of $2^n-1$ consists of $n$ ones. This is because the binary expansion of $2^n$ consists of a one followed by $n$ zeroes. This is similar to $10^3-1 = 999$ in decimal.

If we want these $n$ bits to be the left $n$ bits out of $m$ bits, then we need to add $m-n$ zeroes to the right. This is the same as multiplying everything by $2^{n-m}$. Compare $100 \cdots 54 = 5400$. This operation is usually known as left shift, and many languages support it natively. For example, in C you would use the following code to generate the mask:


  ((1 &lt;&lt; 24) - 1) &lt;&lt; (32-24)