I am trying to convert a Hex string to an 8-bit signed integer array in Powershell.
I am using the following function to convert a Hex string, such as A591BF86E5D7D9837EE7ACC569C4B59B, to a byte array which I then need to convert to a 8-bit signed integer array.
Function GetByteArray {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[String]
$HexString
)
$Bytes = [byte[]]::new($HexString.Length / 2)
For($i=0; $i -lt $HexString.Length; $i+=2){
$Bytes[$i/2] = [convert]::ToByte($HexString.Substring($i, 2), 16)
}
$Bytes
}
After using the function the hex is converted to a byte array such as this:
I need to take the unsigned byte array and convert o to 8bit signed byte array, like the one below:
Is this possible? If so how can it be implemented?
I've tried using the BitConverter class but, as far as I saw, it can only convert to int16.
Thanks in advance