1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2025-12-24 21:51:38 +02:00
Files
SharedScripts/ConvertTo-BinaryString/ConvertTo-BinaryString.ps1
Jaap Brasser b050f54c27 Added pipeline support and fixed padding 1️⃣1️⃣0️⃣1️⃣
2021-01-10 00:12:02 +01:00

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 ' ')
}
}