IPV4二进制显示

Sometimes it may be useful to display an IPv4 address bit by bit, for example, to compare it with a subnet mask. Here's another example of just how flexible PowerShell is because it only takes one line:

$ipV4='192.168.12.33'-join ($ipV4.Split('.') |ForEach-Object {[System.Convert]::ToString($_,2).PadLeft(8,'0')})

The result looks like this:

You can also change the code a little:

$ipV4.Split('.') |ForEach-Object {
    '{0,5} : {1}'-f$_, [System.Convert]::ToString($_,2).PadLeft(8,'0')
 } 

Now the result looks like this:

http://powershell.com/cs/blogs/tips/archive/2013/05/23/displaying-ipv4-address-as-binary.aspx

原文地址:https://www.cnblogs.com/fuckcn/p/3096513.html