title: How to convert netmask to network prefix length?
body: <p>I am doing some programming, I wanna convert the netmask to network prefix length.</p>
  
  <p>For example 255.255.255.0 ----> 24.</p>
  
  <p>Finally I write some code to do so.</p>
  
  <pre><code>const char *network = "255.255.255.0";
  int n = inet_addr(netowrk);
  int i = 0;
  while (n &gt; 0) {
      n = n &lt;&lt; 1;
      i++;
  </code></pre>
  
  <p>}</p>
  
  <p>i will be the network count</p>