Last active
November 26, 2024 21:11
-
-
Save amigus/555b34d0b1c872c33f3fee55c7ed17e9 to your computer and use it in GitHub Desktop.
Byte Calculation Functions; use: Invoke-Expression (&{curl -Ls https://mig.us/bcfps1 | Out-String}); (44040192 | bytesfromk | bytestogigs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertFrom-BytesByFactor { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory)][int]$Factor, | |
[Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount | |
) | |
process { | |
Write-Debug ("Rounding the result of $Amount * 1024 ^ $Factor") | |
[Convert]::ToInt64([Math]::Round($Amount * [Math]::Pow(1024, $Factor))) | |
} | |
} | |
function ConvertTo-BytesByFactor { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory)][int]$Factor, | |
[Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount | |
) | |
process { | |
Write-Debug ("Rounding the result of $Amount / 1024 ^ $Factor") | |
[Convert]::ToInt64([Math]::Round($Amount / [Math]::Pow(1024, $Factor))) | |
} | |
} | |
function ConvertFrom-Gigabytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertFrom-BytesByFactor 3 $Amount | |
} | |
Set-Alias -Name "bytesfromgigs" -Value ConvertFrom-Gigabytes -Option AllScope | |
function ConvertFrom-Megabytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertFrom-BytesByFactor 2 $Amount | |
} | |
Set-Alias -Name "bytesfrommegs" -Value ConvertFrom-Megabytes -Option AllScope | |
function ConvertFrom-Kiloytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertFrom-BytesByFactor 1 $Amount | |
} | |
Set-Alias -Name "bytesfromk" -Value ConvertFrom-Kiloytes -Option AllScope | |
function ConvertTo-Gigabytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertTo-BytesByFactor 3 $Amount | |
} | |
Set-Alias -Name "bytestogigs" -Value ConvertTo-Gigabytes -Option AllScope | |
function ConvertTo-Megabytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertTo-BytesByFactor 2 $Amount | |
} | |
Set-Alias -Name "bytestomegs" -Value ConvertTo-Megabytes -Option AllScope | |
function ConvertTo-Kiloytes { | |
param([Parameter(Mandatory, ValueFromPipeline)][Int64]$Amount) ConvertTo-BytesByFactor 1 $Amount | |
} | |
Set-Alias -Name "bytestok" -Value ConvertTo-Kiloytes -Option AllScope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment