Calculating the number of bits in a Subnet Mask in C#

后端 未结 5 666
借酒劲吻你
借酒劲吻你 2021-01-14 06:47

I have a task to complete in C#. I have a Subnet Mask: 255.255.128.0.

I need to find the number of bits in the Subnet Mask, which would be, in this case, 17.

5条回答
  •  花落未央
    2021-01-14 07:30

    string ip = "255.255.128.0";
    string a = "";
    ip.Split('.').ToList().ForEach(x => a += Convert.ToInt32(x, 2).ToString());
    int ones_found = a.Replace("0", "").Length;
    

提交回复
热议问题