Canonicalize CIDR: Difference between revisions

Content added Content deleted
(Added Wren)
Line 43: Line 43:
function canonCIDR(cidr::String)
function canonCIDR(cidr::String)
ip = split(cidr, "/")
ip = split(cidr, "/")
ip4 = IPv4(UInt64(IPv4(ip[1])) & 0xfffffefe)
dig = length(ip) > 1 ? 2^(32 - parse(UInt64, ip[2])) : 1
return length(ip) == 1 ? "$ip4" : "$ip4/$(ip[2])" # return as a string
ip4 = IPv4(UInt64(IPv4(ip[1])) & (0xffffffff - dig + 1))
return length(ip) == 1 ? "$ip4" : "$ip4/$(ip[2])"
end
end


Line 52: Line 53:
87.70.140.0/22
87.70.140.0/22
</pre>
</pre>



=={{header|Perl}}==
=={{header|Perl}}==