1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2026-04-18 19:01:56 +02:00

Added convertfrom-binarystring function 1️⃣0️⃣1️⃣1️⃣1️⃣0️⃣0️⃣0️⃣

This commit is contained in:
Jaap Brasser
2021-01-05 17:55:38 +01:00
parent e2fb9e407d
commit 0a51c753b4
@@ -0,0 +1,31 @@
function ConvertFrom-BinaryString {
<#
.SYNOPSIS
Function to parse an array of binary strings to characters
.EXAMPLE
ConvertFrom-BinaryString -String 1101010, 1100001, 1100001, 1110000, 1100010, 1110010, 1100001, 1110011, 1110011, 1100101, 1110010
Output jaapbrasser
.EXAMPLE
$mystring = 'https://jaapbrasser.com'
$mybinaryarray = [int32[]]$mystring.tochararray() | % {[convert]::ToString($_,2)}
ConvertFrom-BinaryString -String $mybinaryarray
Take a string, convert it to int32 followed by conversion to an array base 2, binary strings. Then use ConvertFrom-BinaryString to convert it back
.EXAMPLE
ConvertFrom-BinaryString -String 11000101, 10000001, 01100001, 01110011, 01101001, 01100011, 01100101, 00100000, 01110000, 01101111, 01111010, 01100100, 01110010, 01100001, 01110111, 01101001, 01100001, 01101010, 11000100, 10000101, 00100000, 01110111, 01101001, 01101100, 01101011, 01101001
Output the content of this array of binary string to characters
#>
param(
[string[]] $String
)
$Output = $String | ForEach-Object {
[char][convert]::ToInt32($_,2)
}
return (-join $Output)
}