Created
December 26, 2017 14:35
-
-
Save aw/11e5e59b107feecd1a5b74cdaba2a54c to your computer and use it in GitHub Desktop.
Convert a CIDR to Subnet Netmask address in PicoLisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MIT Licensed | |
# | |
#(c) 2017 Alexander Williams, Unscramble <[email protected]> | |
# | |
# IPv4 "24" -> "255.255.255.0" | |
[de cidr-to-netmask (Mask) | |
(let (Pos (- 5 (/ Mask 8)) | |
Val (& (>> (- (- 8 (% Mask 8))) 255) 255) ) | |
(glue "." | |
(let N 5 | |
(make | |
(loop | |
(cond | |
((= N Pos) (link Val)) | |
((< N Pos) (link 0)) | |
((> N Pos) (link 255)) ) | |
(T (=1 (dec 'N))) ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage examples