PowerShell: Number Input

By Xah Lee. Date: .

Syntax for Hexadecimal Number

0xhexadecimal_digits

$x = 0xff
Write-Host $x
# 255

Syntax for Binary Number

0bbinary_digits

$x = 0b11
Write-Host $x
# 3

Scientific Notation

$x = 2e3
Write-Host $x
# 2000

$x = 2e4
Write-Host $x
# 20000

Convenient Input for kilobyte, megabyte, gigabyte

# number input form
# kilobyte, megabyte, gigabyte

$x1 = 1kb
$x1
# 1024
[Math]::Pow(2,10)
# 1024

$x2 = 1mb
$x2
# 1048576
[Math]::Pow(2,20)
# 1048576

$x3 = 1gb
$x3
# 1073741824
[Math]::Pow(2,30)
# 1073741824