title: Using SQL to determine cidr value of a subnet mask
body: <p>I'd like to find a way to do a SQL query that will calculate the cidr (bit representation) of a subnet mask stored in the database.  So for example, I've got either 255.255.255.0 or its decimal value (4294967040) stored in the database.  I'd like to do a select and get back /24 representation via the query.</p>
  
  <p>I've done things like the following to determine the last IP of a subnet so I'm hoping to do something similar to determine the cidr representation of a mask.</p>
  
  <pre><code>select concat(inet_ntoa(ip_addr),'-',
      inet_ntoa(ip_addr+(POWER(2,32)-ip_mask-1))) range 
  from subnets 
  order by ip_addr
  </code></pre>
  
  <p>Preferably this would be a SQL statement that would work under mysql, postgres, oracle etc.</p>