You've already forked SharedScripts
mirror of
https://github.com/jaapbrasser/SharedScripts.git
synced 2025-12-24 21:51:38 +02:00
29 lines
760 B
PowerShell
29 lines
760 B
PowerShell
function ConvertTo-BinaryString {
|
|
<#
|
|
.SYNOPSIS
|
|
Function to parse an array of binary strings to characters
|
|
|
|
.EXAMPLE
|
|
ConvertTo-BinaryString -String 'https://jaapbrasser.com'
|
|
|
|
Take a string, converts it to a binary string and returns it
|
|
|
|
.EXAMPLE
|
|
ConvertTo-BinaryString 'https://jaapbrasser.com' -ReturnArray
|
|
|
|
Take a string, converts it to a binary string and returns it as an array
|
|
#>
|
|
[cmdletbinding()]
|
|
param(
|
|
[parameter(ValueFromPipeline)]
|
|
[string] $String,
|
|
[switch] $ReturnArray
|
|
)
|
|
$Output = [int32[]]$String.tochararray() | ForEach-Object {([convert]::ToString($_,2)).PadLeft(8,'0')}
|
|
|
|
if ($ReturnArray) {
|
|
return $Output
|
|
} else {
|
|
return ($Output -join ' ')
|
|
}
|
|
} |