1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2026-06-14 00:14:16 +02:00

Added pipeline support and fixed padding 1️⃣1️⃣0️⃣1️⃣

This commit is contained in:
Jaap Brasser
2021-01-10 00:12:02 +01:00
parent 063fd2b81d
commit b050f54c27
@@ -13,11 +13,13 @@ function ConvertTo-BinaryString {
Take a string, converts it to a binary string and returns it as an array Take a string, converts it to a binary string and returns it as an array
#> #>
[cmdletbinding()]
param( param(
[parameter(ValueFromPipeline)]
[string] $String, [string] $String,
[switch] $ReturnArray [switch] $ReturnArray
) )
$Output = [int32[]]$String.tochararray() | ForEach-Object {[convert]::ToString($_,2).PadRight(8,0)} $Output = [int32[]]$String.tochararray() | ForEach-Object {([convert]::ToString($_,2)).PadLeft(8,'0')}
if ($ReturnArray) { if ($ReturnArray) {
return $Output return $Output