Canonicalize CIDR: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 299: Line 299:
<pre>$ canonicalize_cidr.raku 87.70.141.1/22
<pre>$ canonicalize_cidr.raku 87.70.141.1/22
87.70.140.0/22</pre>
87.70.140.0/22</pre>

=={{header|REXX}}==
<lang rexx>/*REXX pgm canonicalizes IPv4 addresses that are in CIDR notation (dotted─dec/network).*/
parse arg z . /*obtain optional argument from the CL.*/
if z=='' | z=="," then z= '87.70.141.122/22' /*Not specified? Then use the default.*/
parse var z # '/' -0 mask /*get the address nodes & optional mask*/
#= translate(#, , .) /*elide periods from IPv4 address nodes*/
$= /*initialize the to-be reassembled IPv4*/
do j=1 for words(#); x= word(#, j) /*process each of the address nodes. */
if x//2 then x= x - 1 /*Is low─order bit on? Then remove it.*/
$= $ x /*reconstruct (by abutment) IPv4 nodes.*/
end /*j*/ /*(REXX stores it's numbers in decimal)*/
/*stick a fork in it, we're all done. */
say ' original IPv4 address: ' z /*display the original IPv4 address. */
say ' canonicalized address: ' translate( space($), ., " ") || mask /*canonicalized.*/</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
original IPv4 address: 87.70.141.122/22
canonicalized address: 86.70.140.122/22
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==