Search notes:

PowerShell: arithmetic operators

The arithmetic operators in PowerShell are: +, - *, /, %, ++, --, +=, -=, *=, /=, -shl, -shr, -band, -bnot, -bor, -xor
Apart from the expected usages of the arithmetic operators on numbers, there are also a few that are worth mentioning:
'Text'  * 4                         # repeat string 4 times
(1,2,3) * 2                         # repeat array twice
(1,2,3) + 4                         # add one element to array
(1,2,3) +(4,5)                      # add two elements to array
'XY'    + 'Z'                       # concatenate string
(get-date) + 1                      # date arithmetic (add one tick = a ten-millionth of a second))
(get-date) + (new-timespan -hour 1) # date arithmetic

-bXXX

The operators that start with -b are bitwise operators:
(16+4+1) -bAnd (8+4) #  4 
(16+4+1) -bOr  (8+4) # 29  ( = 1+4+8+16 )
(16+4+1) -bXor (8+4) # 25  ( = 1+  8+16 )
-bnot 4              # -5

-shl, -shr

Shift left and shift right:
1  -shl 4 # 16
16 -shr 3 #  2

Other mathematical operations

The System.Math class provides a few methods that allow to execute other mathematical expressions:
$x = [math]::pow(3,4)

See also

operators

Index