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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758200431, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/operator/arithemtic/index(68): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78