Invert() public method

Inverts IP address value. All 0s are converted to 1s and 1s to 0s
public Invert ( ) : IpAddress
return IpAddress
示例#1
0
        /// <summary>
        /// Returns broadcast address for the objects IP and supplied subnet mask.
        ///
        /// Subnet mask validity is not confirmed before performing the new value calculation so
        /// you should make sure parameter is a valid subnet mask by using <see cref="IpAddress.IsValidMask"/>
        /// method.
        ///
        /// Broadcast address is calculated by changing every bit in the subnet mask that is set to
        /// value 0 into 1 in the address value.
        /// </summary>
        /// <param name="mask">Subnet mask to apply to the object</param>
        /// <returns>New IP address containing broadcast address</returns>
        public IpAddress GetBroadcastAddress(IpAddress mask)
        {
            IpAddress im = mask.Invert();

            byte[] ip  = _data;
            byte[] m   = im.GetData();
            byte[] res = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                res[i] = (byte)(ip[i] | m[i]);
            }
            return(new IpAddress(res));
        }
示例#2
0
        /// <summary>
        ///     Returns broadcast address for the objects IP and supplied subnet mask.
        ///     Subnet mask validity is not confirmed before performing the new value calculation so
        ///     you should make sure parameter is a valid subnet mask by using <see cref="IpAddress.IsValidMask" />
        ///     method.
        ///     Broadcast address is calculated by changing every bit in the subnet mask that is set to
        ///     value 0 into 1 in the address value.
        /// </summary>
        /// <param name="mask">Subnet mask to apply to the object</param>
        /// <returns>New IP address containing broadcast address</returns>
        public IpAddress GetBroadcastAddress(IpAddress mask)
        {
            var im  = mask.Invert();
            var ip  = _data;
            var m   = im.GetData();
            var res = new byte[4];

            for (var i = 0; i < 4; i++)
            {
                res[i] = (byte)(ip[i] | m[i]);
            }
            return(new IpAddress(res));
        }
示例#3
0
 /// <summary>
 /// Returns broadcast address for the objects IP and supplied subnet mask.
 /// 
 /// Subnet mask validity is not confirmed before performing the new value calculation so
 /// you should make sure parameter is a valid subnet mask by using <see cref="IpAddress.IsValidMask"/>
 /// method.
 /// 
 /// Broadcast address is calculated by changing every bit in the subnet mask that is set to
 /// value 0 into 1 in the address value.
 /// </summary>
 /// <param name="mask">Subnet mask to apply to the object</param>
 /// <returns>New IP address containing broadcast address</returns>
 public IpAddress GetBroadcastAddress(IpAddress mask)
 {
     IpAddress im = mask.Invert();
     byte[] ip = _data;
     byte[] m = im.GetData();
     byte[] res = new byte[4];
     for (int i = 0; i < 4; i++)
     {
         res[i] = (byte)(ip[i] | m[i]);
     }
     return new IpAddress(res);
 }