PowerShell offers bitwise shift operators too. We have discussed about “PowerShell – Bitwise Logical Operators” in our previous article. Through this article, we are going to discuss about bitwise shift operators.
Shift left -shl
operator
PowerShell left shift operator shifts the bits left side. This operator takes two operands and left shifts the bits from left side operand, based on the given value in right side operand. By shifting the bit positions, left side; we are increasing the value of the operand. For example, below command shifts the bit positions by 2; results to increase the value from 1 to 4.
PS C:\> 1 -shl 2
4
Shift right -shr
operator
PowerShell right shift operator takes two operands as inputs. It right shifts the bits in the given left hand side operand. The number of bits to right shift should be specified through it’s right side operand. The specified bits will be right shifted in left side operand. This will decrease the value of the operand by shifting the bits, right side. For example, below command decreases the value of 8 to 2 by right shifting the bits.
PS C:\> 8 -shr 2
2
[..] David