February 2019
Intermediate to advanced
626 pages
15h 51m
English
Mathematical operations are executed in a specific order. For example, consider the following two simple calculations:
3 + 2 * 2 2 * 2 + 3
The result of both of the preceding expressions is 7 (2 multiplied by 2, then add 3).
PowerShell, and most other programming languages, will calculate elements of an expression using multiplication (*), division (/), and remainder (%) first. Addition (+) and subtraction (-) are calculated next.
PowerShell has two additional operators in this category, -shl and -shr. These two have the lowest precedence and are only executed after other operations. For example, the result of the following calculation will be 128:
2 * 4 -shl 2 + 2
First, 2 * 4 is calculated, followed by 2 + 2, and then ...
Read now
Unlock full access