Ejemplo n.º 1
0
    public void TestUint128(string aStr, string bStr, byte expected)
    {
        UInt128 a = new UInt128(BigInteger.Parse(aStr));
        UInt128 b = new UInt128(BigInteger.Parse(bStr));

        BitUtilities.FindCommonPrefixSize(a, b).Should().Be(expected);
    }
Ejemplo n.º 2
0
    public static IpAddressNetworkV4 MakeSupernet(IEnumerable <IpAddressNetworkV4> others)
    {
        byte shortestMask = 32;
        bool hadAny       = false;
        uint final        = uint.MaxValue;

        foreach (IpAddressNetworkV4 range in others)
        {
            final &= range._networkAddress.Address;

            byte lowestCommon = BitUtilities.FindCommonPrefixSize(final, range._networkAddress.Address);
            shortestMask = Math.Min(shortestMask, lowestCommon);

            hadAny = true;
        }

        if (!hadAny)
        {
            throw new ArgumentException("Input was empty", nameof(others));
        }

        return(new IpAddressNetworkV4(final, shortestMask));
    }
    public static IpAddressNetworkV6 MakeSupernet(IEnumerable <IpAddressNetworkV6> others)
    {
        bool    hadAny       = false;
        byte    shortestMask = 128;
        UInt128 final        = UInt128.MaxValue;

        foreach (IpAddressNetworkV6 other in others)
        {
            final &= other._networkAddress.Address;

            byte lowestCommon = BitUtilities.FindCommonPrefixSize(final, other._networkAddress.Address);
            shortestMask = Math.Min(shortestMask, lowestCommon);

            hadAny = true;
        }

        if (!hadAny)
        {
            throw new ArgumentException("Input was empty", nameof(others));
        }

        return(new IpAddressNetworkV6(new IpAddressV6(final), shortestMask));
    }
Ejemplo n.º 4
0
 public void TestUint(uint a, uint b, byte expected)
 {
     BitUtilities.FindCommonPrefixSize(a, b).Should().Be(expected);
 }
Ejemplo n.º 5
0
 public byte Current()
 {
     return(BitUtilities.FindCommonPrefixSize(Input.A, Input.B));
 }