While working in PowerShell I needed to convert CIDR notation to IP starting address and subnet mask notation.
Performing a Google search I found this Reddit posting challenge that contained many obscure ways to perform this task.
One that I found particularly interesting was:
$C = 13
[ipaddress](4.GB-(4GB-shr$C))|% i*g
It took me a while to see that -shr$C was merely the PowerShell -shr operator without any white space before the $C variable reference.
I then needed to search to find that % is an alias for Foreach-Object.
By just querying the value of [ipaddress](4.GB-(4GB-shr$C)) I received:
Address : 63743
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
IPAddressToString : 255.248.0.0
Which showed me the properties of the IPAddress object. The result that I need is the IPAddressToString property which I could get by using %| IPAddressToString or somehow coerce PowerShell to emit the object as a string.
Therefore, the question now is what does the syntax % i*g mean?
What is i and g and are we performing multiplication?