Canonicalize CIDR: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (→{{header|11l}}: `(-)` -> `~`) |
(Added Easylang) |
||
Line 813: | Line 813: | ||
<pre>Before canonicalization: 87.70.141.1/22 |
<pre>Before canonicalization: 87.70.141.1/22 |
||
After canonicalization: 87.70.140.0/22</pre> |
After canonicalization: 87.70.140.0/22</pre> |
||
=={{header|EasyLang}}== |
|||
<syntaxhighlight> |
|||
func$ can_cidr s$ . |
|||
n[] = number strsplit s$ "./" |
|||
if len n[] <> 5 |
|||
return "" |
|||
. |
|||
for i to 4 |
|||
if n[i] < 0 or n[i] > 255 |
|||
return "" |
|||
. |
|||
ad = ad * 256 + n[i] |
|||
. |
|||
if n[5] > 31 or n[5] < 1 |
|||
return "" |
|||
. |
|||
mask = bitnot (bitshift 1 (32 - n[5]) - 1) |
|||
ad = bitand ad mask |
|||
for i to 4 |
|||
if r$ <> "" |
|||
r$ = "." & r$ |
|||
. |
|||
r$ = ad mod 256 & r$ |
|||
ad = ad div 256 |
|||
. |
|||
return r$ & "/" & n[5] |
|||
. |
|||
repeat |
|||
s$ = input |
|||
until s$ = "" |
|||
print s$ & " -> " & can_cidr s$ |
|||
. |
|||
# |
|||
input_data |
|||
87.70.141.1/22 |
|||
36.18.154.103/12 |
|||
62.62.197.11/29 |
|||
67.137.119.181/4 |
|||
161.214.74.21/24 |
|||
184.232.176.184/18 |
|||
</syntaxhighlight> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
Line 843: | Line 886: | ||
87.70.140.0/22 |
87.70.140.0/22 |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |