title: How do I found out if a Subnet mask is valid with C#
body: <p>I am in need to find out how I can find out if a provided subnet mask example (255.255.192.0) is a valid subnet mask and return true if it is valid and false if not, I already am checking if the value is over 255. A wrong subnet would be (255.64.0.0)</p>
  <p>It makes a lot of sense in binary (11111111.01000000.00000000.00000000) A subnet can not stop having 1's, and then start having them again. My current idea involves using bitshift, but am unsure how to do it.</p>
  <p>I am not using any libaries and am not allowed for this project</p>
  <p>The code I am using goes something like</p>
  <pre><code>    Console.WriteLine(&quot;Enter a subnet mask&quot;);
      input = Console.ReadLine(); //Enters example of 255.64.0.0 which is invalid
  </code></pre>
  <p>Thanks in advance, ask questions if needed</p>