In my batch file, I am trying to convert a string (%input%) to binary and save the result in a batch variable %varBinary%. My attempt:
for /f "delims=" %%a in ( ' powershell " [System.Text.Encoding]::UTF8.GetBytes(/"%_input%"/) | %{ [System.Convert]::ToString($_,2).PadLeft(8,'0') } " ' ) do set "varBinary=%%a"
echo.%varBinary%
echo."%varBinary%"
echo "%varBinary%"
echo %varBinary%
Output of %varBinary% is always empty. What is wrong here? And how to convert back the Binary to the original string so that it works? Because that didn't work either.
For example, hello should be 0110100001100101011011000110110001101111.