title: Conversion from CIDR notation to IP address/subnet mask (dot-decimal)
body: <pre><code> /*
   * RFC 1518, 1519 - Classless Inter-Domain Routing (CIDR)
   * This converts from "prefix + prefix-length" format to
   * "address + mask" format, e.g. from xxx.xxx.xxx.xxx/yy
   * to xxx.xxx.xxx.xxx/yyy.yyy.yyy.yyy.
   */
  static private String normalizeFromCIDR(final String netspec)
  {
      final int bits = 32 - Integer.parseInt(netspec.substring(netspec.indexOf('/')+1));
      final int mask = (bits == 32) ? 0 : 0xFFFFFFFF - ((1 &lt;&lt; bits)-1); 
  
      return netspec.substring(0, netspec.indexOf('/') + 1) +
              Integer.toString(mask &gt;&gt; 24 &amp; 0xFF, 10) + "." +
              Integer.toString(mask &gt;&gt; 16 &amp; 0xFF, 10) + "." +
              Integer.toString(mask &gt;&gt;  8 &amp; 0xFF, 10) + "." +
              Integer.toString(mask &gt;&gt;  0 &amp; 0xFF, 10);
  }
  </code></pre>
  
  <p>This is a function in apache james to convert the ip to the specified format. Can you please explain what's happening inside the function. Confused with this bit shifting and conversion.
  Thanks in Advance.</p>