Canonicalize CIDR: Difference between revisions

Content deleted Content added
m C - made code a bit shorter
Markjreed (talk | contribs)
Add more examples.
Line 16:
The example address, 87.70.141.1, translates into 01010111010001101000110100000001 in binary notation zero-padded to 32 bits. The /22 means that the first 22 of those bits determine the match; the final 10 bits should be 0. But they instead include two 1 bits: 0100000001. So to canonicalize the address, change those 1's to 0's to yield 01010111010001101000110000000000, which in dotted-decimal is 87.70.140.0.
 
;More examples for testing
 
<pre>36.18.154.103/12 → 36.16.0.0/12
62.62.197.11/29 → 62.62.197.8/29
67.137.119.181/4 → 64.0.0.0/4
161.214.74.21/24 → 161.214.74.0/24
184.232.176.184/18 → 184.232.128.0/18</pre>
=={{header|C}}==
This solution uses only the standard library. On POSIX platforms one can use the functions