Continuing our look at binary operations I decided I wanted to be able to perform the bitwise operations – band, bor, bxor and get the results back as binary. We already have operators for these actions in PowerShell so its just a matter of wrapping the appropriate conversion code around them. I’ll show the code for band here. The other two are very similar and will be available in the module when I post it on codeplex.
Two binary numbers as input as we saw in the addition\subtraction functions. I have changed the names to be consistent across the module. Perform the standard checks and then convert them to decimal and perform the band. The result is converted back to binary – padding left with zeros if required.
I decided to show the inputs and output if required – may be a good learning tool to understand this.
usage is straight forward
PS> Get-BinaryAND -inputvalue1 1010 -inputvalue2 0011
PS> Get-BinaryAND -inputvalue1 10111010 -inputvalue2 01110011 -showsum
The module contents stand at
I need to add a couple of functions to do hex addition and subtraction and then its done