February 2019
Intermediate to advanced
626 pages
15h 51m
English
The -shl and -shr operators were introduced with PowerShell 3.0. These operators perform bit-shifting.
The possible bit values for a byte can be represented as a table:
|
Bit position |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
|
Bit value |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
For a numeric value of 78, the following bits must be set:
|
Bit value |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
On or off |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
0 |
When a left shift operation is performed, every bit is moved one to the left. Say we run this expression:
78 -shl 1
The result is 156, which is expressed in this bit table:
|
Bit value |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
Before shift |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
Read now
Unlock full access