Canonicalize CIDR: Difference between revisions

m
→‎{{header|REXX}}: changed a comment, updated example nodes.
(Add more examples.)
m (→‎{{header|REXX}}: changed a comment, updated example nodes.)
Line 434:
parse arg a . /*obtain optional argument from the CL.*/
if a=='' | a=="," then a= '87.70.141.1/22' , /*Not specified? Then use the defaults*/
'10036.6818.0154.18103/1812' ,
'1062.462.30197.7711/3029' ,
'1067.207137.219119.251181/324' ,
'10161.207214.21974.25121/24' ,
'110184.200232.21176.184/418' ,
'10.11.12.13/8'
 
do i=1 for words(a); z= word(a, i) /*process each IPv4 address in the list*/
Line 453 ⟶ 452:
##= left(##, 32, 0) /*replace cropped bits with binary '0's*/
do j=8 by 8 for 4 /* [↓] parse the four nodes of address*/
$= $ || . || b2d(substr(##, j-7, 8)) /*reconstitute the decimal nodes. */
end /*j*/ /* [↑] and insert a dot between nodes.*/
say /*introduce a blank line between IPv4's*/
Line 469 ⟶ 468:
canonicalized address: 87.70.140.0/22
 
original IPv4 address: 10036.6818.0154.18103/1812
canonicalized address: 10036.6816.0.0/1812
 
original IPv4 address: 1062.462.30197.7711/3029
canonicalized address: 1062.462.30197.768/3029
 
original IPv4 address: 1067.207137.219119.251181/324
canonicalized address: 1064.2070.2190.2510/324
 
original IPv4 address: 10161.207214.21974.25121/24
canonicalized address: 10161.207214.21974.2510/24
 
original IPv4 address: 110184.200232.21176.184/418
canonicalized address: 96184.0232.0128.0/418
 
original IPv4 address: 10.11.12.13/8
canonicalized address: 10.0.0.0/8
</pre>